Macro definition method for macro-parameter columns with variable target parameters.

Source: Internet
Author: User

The C ++ compiler accepts# DefinePreprocessing Program commands.


#define identifier (...) replacement_list#define identifier (identifier_list, ...) replacement_list

If the listed macro parameters end with a ellipsis, more macro parameters except macro parameters can be called. Other parameters (including commas) are collected into a string, and the macro replaces the name in the list._ VA_ARGS __This string can be referenced. The following example shows how to use the macro of the variable parameter list.


#define debug(...) fprintf(stderr, __VA_ARGS__)#define showlist(...) puts(#__VA_ARGS__)#define report(test, ...) ((test)?puts(#test):\                        printf(__VA_ARGS__))debug(“Flag”);debug(“X = %d\n”,x);showlist(The first, second, and third items.);report(x>y, “x is %d but y is %d”, x, y);

The result is as follows:


fprintf(stderr, “Flag”);fprintf(stderr, “X = %d\n”, x);puts(“The first, second, and third items.”);((x>y)?puts(“x>y”):printf(“x is %d but y is %d”, x, y));
 

Related Article

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.