Variable Parameter macro _ VA_ARGS __

Source: Internet
Author: User


The macro definition uses variable parameters, which makes it much easier to use. For details, refer to the msdn example:

 

Support for variadic macros was introduced in Visual C ++ 2005.

// Variadic_macros.cpp
# Include <stdio. h>
# Define EMPTY

# Define CHECK1 (x,...) if (! (X) {printf (_ VA_ARGS __);}
# Define CHECK2 (x,...) if (x) {printf (_ VA_ARGS __);}
# Define CHECK3 (...) {printf (_ VA_ARGS __);}
# Define MACRO (s,...) printf (s, _ VA_ARGS __)

Int main (){
CHECK1 (0, "here % s", "are", "some", "varargs1 (1) \ n ");
CHECK1 (1, "here % s", "are", "some", "varargs1 (2) \ n"); // won't print

CHECK2 (0, "here % s", "are", "some", "varargs2 (3) \ n"); // won't print
CHECK2 (1, "here % s", "are", "some", "varargs2 (4) \ n ");

// Always invokes printf in the macro
CHECK3 ("here % s", "are", "some", "varargs3 (5) \ n ");

MACRO ("hello, world \ n ");
// MACRO ("error \ n", EMPTY); wocould cause C2059
}

Here are some varargs1 (1)
Here are some varargs2 (4)
Here are some varargs3 (5)
Hello, world

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.