Variable-parameter macros

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.