arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Preprocessor: comma deletion by token-pasting operator

Open ehaas opened this issue 3 years ago • 0 comments

If ## appears between a comma and __VA_ARGS__ in a function-like macro, and the variable argument is omitted, the comma will be deleted in the expansion:

#define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
eprintf("test");
eprintf("test", 2);

expands to:

fprintf (stderr, "test");
fprintf (stderr, "test", 2);

GCC does not issue any warnings; clang issues a pedantic warning warning: token pasting of ',' and __VA_ARGS__ is a GNU extension [-Wgnu-zero-variadic-macro-arguments]

ehaas avatar Jul 28 '22 16:07 ehaas