Variable-parameter macros ... and __va_args__

Source: Internet
Author: User

__VA_ARGS__ is a variable-parameter macro that few people know about this macro, which is the new C99 specification, and currently appears to be supported only by GCC (VC6.0 compiler does not support it).
The implementation idea is that the last parameter in the argument list in the macro definition is an ellipsis (that is, three points). This way the predefined macro _ _va_args_ _ can be used in the replacement section, replacing the string represented by the ellipsis. Like what:
#define PR (...) printf (__va_args__)
int main ()
{
int wt=1,sp=2;
PR ("hello\n");
PR ("weight =%d, shipping =%d", WT,SP);
return 0;
}
Output Result:
Hello
Weight = 1, shipping = 2
Ellipses can only replace the most later macro parameters.
#define W (x,..., y) Error!

Transferred from: http://www.cnblogs.com/pengyingh/articles/2407265.html

Variable-parameter macros ... and __va_args__

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.