Page 3 of 3

Re: NXC: functions with different numbers of parameters?

Posted: 03 Aug 2012, 12:02
by HaWe
thank you John, the max negative float thing seems to be fixed!

Back to topic, I dont see why this works:

Code: Select all

#define printf1( _x, _y, _fmt, _val, style) {  \
  string sval = FormatNum(_fmt, _val); \
  TextOut(_x, _y, sval, style); \
}

task main() {
   printf1(0,40, "%4d", 5, DRAW_OPT_INVERT);
   while(1);

}
but that not:

Code: Select all

#define printf1( _x, _y, _fmt, _val, style=DRAW_OPT_NORMAL) {  \
  string sval = FormatNum(_fmt, _val); \
  TextOut(_x, _y, sval, style); \
}

task main() {
   printf1(0,40, "%4d", 5, DRAW_OPT_INVERT);
   while(1);

}
and that also not:

Code: Select all

#define printf1( _x, _y, _fmt, _val, int style=DRAW_OPT_NORMAL) {  \
  string sval = FormatNum(_fmt, _val); \
  TextOut(_x, _y, sval, style); \
}

task main() {
   printf1(0,40, "%4d", 5, DRAW_OPT_INVERT);
   while(1);

}

Re: NXC: functions with different numbers of parameters?

Posted: 03 Aug 2012, 15:59
by afanofosc
The support in NXC for optional arguments in functions by providing default values in the function declaration does not work at all in the preprocessor, i.e., with #define. I don't think that is likely to ever change.

John Hansen

Re: NXC: functions with different numbers of parameters?

Posted: 03 Aug 2012, 16:53
by HaWe
thx, I see!