Variable parameter macro definition in GNU C

Three forms of variable parameter macro definitions are supported in GNU C, as follows:

#define debug1(format, ...) fprintf (stderr, format, __VA_ARGS__)

#define debug2(format, args...) fprintf (stderr, format, args)

#define debug3(format, ...) fprintf (stderr, format, ## __VA_ARGS__)

Among them, when the variable parameter list is empty, the third definition method needs to be used, as shown below:

debug1("%s:%d\n", __FILE__, __LINE__);  // ok

debug2("%s:%d\n", __FILE__, __LINE__);  // ok

debug3("%s:%d\n", __FILE__, __LINE__);  // ok

debug1("debug1\n"); // error

debug2("debug2\n"); // error

debug3("debug3\n"); // ok

 

Guess you like

Origin blog.csdn.net/choumin/article/details/115031066