Arduino Compiler and Variadic Macro Arguments

Does the Arduino compiler support ANY form of variadic macro arguments? I've tried a half dozen different formats for this, some of which were explicitly claimed to be unique to gnu c++, but NONE of them work.

Is there another form I'm missing?

Regards,
Ray L.

Should. I recall various people using them for debug stuff.

Post an example.

I've tried every variation I can find, including these:

#define BLORT1(s) { printf(s); }
#define BLORT2(...) { printf(VA_ARGS); }
#define BLORT3(s, ...) { printf(s, VA_ARGS); }
#define BLORT3(s, ...) { printf(s, ## VA_ARGS); }
#define BLORT4(s, args...) { printf(s, args); }

So far, NOTHING has worked.

Regards,
Ray L.

These work.

// DebugMacros.h

/* Example of use:
   #define DEBUG          // <-----<<<< this line must appear before the include line
   #include <DebugMacros.h>
*/

//If you comment the line:  #define DEBUG
//The Macro lines are defined as blank, thus would be ignored by the compiler.
//If the line is NOT commented, these macros will be included in the sketch.
// examples:
// This  converts to         >>>>----->         This OR a Blank Line. 
//---–----------------------------------------------------------------------------------------
// DPRINTLN("Testing123");   >>>>----->     Serial.println("Testing123"); 
// DPRINTLN(0xC0FFEEul,DEC); >>>>----->     Serial.println(0xC0FFEEul,DEC);
// DPRINTLN(12648430ul,HEX); >>>------>     Serial.println(12648430ul,HEX);
// DPRINTLNF("This text came from flash");  Serial.println(F("This text came from flash"));
// DPRINT(myVariable);       >>>>----->     Serial.print(myVariable);
// DELAY(100);               >>>>----->     delay(100);
// SERIALBEGIN(9600);        >>>>----->     Serial.begin(9600);
// PINMODE(13,OUTPUT);       >>>>----->     pinMode(13,OUTPUT);
// TOGGLEd13;                >>>>----->     PINB = 0x20;  // D13 Toggle,for UNO ONLY
 
#ifdef DEBUG
//#define DPRINT(args...)  Serial.print(args)             //OR use the following syntax:
#define SERIALBEGIN(...)   Serial.begin(__VA_ARGS__)
#define DPRINT(...)        Serial.print(__VA_ARGS__)
#define DPRINTLN(...)      Serial.println(__VA_ARGS__)
#define DRINTF(...)        Serial.print(F(__VA_ARGS__))
#define DPRINTLNF(...)     Serial.println(F(__VA_ARGS__)) //Printing text using the F macro
#define DELAY(...)         delay(__VA_ARGS__)
#define PINMODE(...)       pinMode(__VA_ARGS__)
#define TOGGLEd13          PINB = 0x20                    //For the UNO only
 
#else
#define SERIALBEGIN(...)   //blank line
#define DPRINT(...)        //blank line
#define DPRINTLN(...)      //blank line
#define DPRINTF(...)       //blank line
#define DPRINTLNF(...)     //blank line
#define DELAY(...)         //blank line
#define PINMODE(...)       //blank line
#define TOGGLEd13          //blank line 
 
#endif

Well.... This is annoying! I was getting spoofed. The first macro I created was:

#define INFO(...) { Console->printf("INFO: "); Console->printf(VA_ARGS); }

When I used it like this:

INFO("Blew Chunk in %s\n", s);

I got the error that INFO required one argument but I passed two.

Turns out, there was already a, INFO macro in one of the libraries that was over-riding mine! I changed mine from INFO to INFORM, and it now works!

Thanks!

Regards,
Ray L.

For some reason I have a recollection that a do/while eliminates a potential problem...

#define INFORM(...)  do { Console->printf("INFO: "); Console->printf(__VA_ARGS__); } while ( false )

The optimizer gladly eliminates the actual loop.

#define FOO(x) { ... }

if (blah) FOO(7);
else FOO(77);

expands to

if (blah) { ... };
else { ... };

which gives an "else without if" error. "do { ... } while (0)" will give proper syntax. Using { } with if and else will also avoid the problem.