Macros and variable parameters

Source: Internet
Author: User

 Macros and variable parameters

 

Let's talk about macros today. What? Can macros also be variable parameters? Yes, you have not heard the error. The macro with parameters is the same as the function, and variable parameters are also supported. The following describes a small program.

CPP Code
  1. # Include <stdio. h>
  2. # Include <stdlib. h>
  3. # Define outscreen (MSG,...) printf (MSG ,__ va_args __)
  4. Int main (INT argc, char * argv [])
  5. {
  6. Outscreen ("Hello world! N % s "," _ this is a macro! N ");
  7. Return 0;
  8. }

 

 

The Macro of this variable parameter is added in the new c99 specification. Currently, only GCC is supported (not supported by the vc6.0 compiler ).

CPP Code
  1. # Define outscreen (MSG,...) printf (MSG, _ va_args __)
  2. Int main (INT argc, char * argv [])
  3. {
  4. Outscreen ("Hello world! N % s "," _ this is a macro! N ");
  5. Return 0;
  6. }

 


Let's make a slight modification to the above Code and make it look like the following.

CPP Code
  1. # Define outscreen (MSG,...) printf (MSG, _ va_args __)
  2. Int main (INT argc, char * argv [])
  3. {
  4. Outscreen ("Hello world! ");
  5. Return 0;
  6. }

 

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.