C Language # # __VA_ARGS__ macro

Source: Internet
Author: User

In GNU C, a macro can accept a variable number of arguments, just like a function

__va_args__ can be regarded as the ... Assign a value to the macro

 //  Note you can't call ABC ()   #include  <stdio.h> #include  <stdarg.h> #define  ABC (...) printf (__va_args__) /*  void ABC (...) {//printf (__va_args__);}  */ int   Main () {ABC ( "  %s\n  , "  hello      );  return  0  ;}  

Note that the macro can accept mutable parameters rather than functions (the variable number of parameters involved in the function requires va_list).

In addition __va_args__ is a variable parameter of the macro, very few people know this macro, this variable parameter of the macro is new C99 specification, it seems that only GCC support (VC6.0 compiler does not support). The macro front Plus # #的作用在于, when the number of variable parameters is 0 o'clock, here the # #起到把前面多余的 "," remove the effect, otherwise it will compile error, you can try.

C Language # # __VA_ARGS__ macro

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.