#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
Here ‘...’ is a variable argument. In the invocation of such a macro, it represents the zero or more tokens until the closing parenthesis that ends the invocation, including any commas. This set of tokens replaces the identifier __VA_ARGS__ in the macro body wherever
it appears.
等价于:
#define debug(format, args...) fprintf (stderr, format, args)
但是,如果变参的个数为0, compiler will complain。
debug(“what is this”);
debug(“what is this”,);
一个解决办法:
#define debug(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
typedef enum _NF_MSG_TYPE_T
{ERROR = 0, /**< Error messages.*/
WARNING, /**< Warnings.*/
INFO, /**< Normal messages.*/
INVALID, /**< Invalid type.*/
} NF_MSG_TYPE_T;
/**
@brief
NF_MSG
Define macro which could print out message in both DEBUG and RELEASE version.
*/
#define NF_MSG(type, format, args...) \
{ \
if (ERROR == type) \
{ \
fprintf (stderr, "ERROR:"); \
} \
else if (WARNING == type) \
{ \
fprintf (stderr, "WARNING:"); \
} \
else if (INFO == type) \
{ \
fprintf (stderr, "INFO:"); \
} \
else \
{ \
} \
fprintf (stderr, format, ##args); \
}