arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Preprocessor: __VA_OPT__ function macro

Open ehaas opened this issue 3 years ago • 0 comments

Description here https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

clang only supports this in C++ mode with -std=c++2a. gcc supports it in all C standards but issues a pedantic warning warning: __VA_OPT__ is not available until C++2a in non-GNU standards.

Example usage:

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

After preprocessor expansion these become:

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

ehaas avatar Jul 28 '22 16:07 ehaas