NXC: functions with different numbers of parameters?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post 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);

}
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: functions with different numbers of parameters?

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

thx, I see!
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest