Reference from:
Http://www.cnblogs.com/lixiaohui-ambition/archive/2012/08/21/2649052.html
http://blog.csdn.net/aobai219/article/details/6092292
Http://www.cnblogs.com/MarvinGeng/archive/2012/07/19/2598923.html
Thank Lizezheng, Tonggetongge, Marvingeng Guide!
Variable-parameter macros:
1. Variable-parameter macros are supported by the C99 specification, as follows:
#define DEBUG (...) printf (__va_args__)
The default number represents a table of parameters that can be changed. Use the reserved name __va_args__ to pass parameters to the macro. When the macro's call is expanded, the actual parameters are passed to printf () .
If the default number is preceded by a comma, it is written in the following form:
#define DEBUG (format, ...) printf (format, # #__VA_ARGS__)
' # # ' means that if the variable parameter is ignored or empty, the preprocessor (preprocessor) is removed from the comma in front of it.
2. Compiler built-in macro definition:
Standard scheduled macros for ANSI C:
__date__: Replace with the current date in the format of "Month Day Year", type string
__FILE__: Replace with current source file name includes path, type is string
__LINE__: Replaced with the current line number, can be set in conjunction with #line, #line之后的数字代表 the line number of the next line, followed by the line number, and so on, the type is an integer value.
__STDC__: This identity is assigned a value of 1 when a program is required to strictly adhere to the ANSI C standard
__TIME__: Replace with the current time in "time: minutes: Seconds" format, type string
__TIMESTAMP__: Replace with the format "Day of the Week: minute: Second year" as the last time the current source file was modified, type string
For a detailed description, see:
Https://msdn.microsoft.com/en-us/library/b0084kay (vs.80). aspx
3. A combination of the two can generate useful debug output macros, such as:
1 #define __debug__ 2#ifdef __debug__ 3#define DEBUG (format, ...) printf ("Line:%4d time :" __time__ " " format "\ n", __line__,# #__VA_ARGS__) 4#else 5#define DEBUG (format,...) 6 #endif
View Code
Variable-parameter macros