23,120
社区成员
发帖
与我相关
我的任务
分享
#if defined(__GNUC__) && (__GNUC__ < 3)
#define LOG_ERROR(args...) \
fprintf( stdout , "Error: %u:%s\n", __LINE__, __FILE__); \
fprintf( stdout , ## args ); \
fprintf( stdout , "\n" );
#else
#define LOG_ERROR(...) \
fprintf( stdout , "Error: %u:%s\n", __LINE__, __FILE__); \
fprintf( stdout , __VA_ARGS__); \
fprintf( stdout , "\n" );
#endif
[no]gnu_varargmacros This option is similar to -qlanglvl=varargmacros. The main differences are:
* An optional variable argument identifier may precede the ellipsis, allowing that identifier to be used in place of the macro __VA_ARGS__ . Whitespace may appear between the identifier and the ellipsis.
* The variable argument can be omitted.
* If the token paste operator (##) appears between the comma and the variable argument, the preprocessor removes the dangling comma (,) if the variable argument is not provided.
* The macro __IBM_MACRO_WITH_VA_ARGS is defined to 1.
Example 1 - Simple substitution:
#define debug(format, args...) printf(format, args)
debug("Hello %s\n", "Chris");
preprocesses to:
printf("Hello %s\n", "Chris");
Example 2 - Omitting the variable argument:
#define debug(format, args...) printf(format, args)
debug("Hello\n");
preprocesses to the following, leaving a dangling comma:
printf("Hello\n",);
Example 3 - Using the token paste operator to remove a dangling comma when the variable argument is omitted:
#define debug(format, args...) printf(format, ## args)
debug("Hello\n");
preprocesses to:
printf("Hello\n");
#include <stdio.h>
#define log_(...) \
do {\
printf(__VA_ARGS__);\
} while(0)
main()
{
log_("%d, %d\n", 1, 2);
log_("%s", "hello\n");
}