The following code causes "expected primary-expression before ‘)’ token" error when trying to compile it on Linux:
#define PRINTF(args, ...) printf((args), __VA_ARGS__)
void test( )
{
PRINTF( "test" );
}
The same code works fine on Windows. I am not sure what the problem is.
Solution:
adding ## before __VA_ARGS__ solves the problem
In Standard C, #define PRINTF(args, ...) means that any invocation of the PRINTF macro must supply at least two arguments.
The GNU preprocessor offers two extensions:
, ## __VA_ARGS__ is allowed in the expansion with meaning:
, __VA_ARGS__.If you see a compiler accept your original code, it means that there is a preprocessor in use that offers non-standard extensions. Conversely, your "solution" might not work on some implementations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With