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
- # Include <stdio. h>
- # Include <stdlib. h>
- # Define outscreen (MSG,...) printf (MSG ,__ va_args __)
- Int main (INT argc, char * argv [])
- {
- Outscreen ("Hello world! N % s "," _ this is a macro! N ");
- Return 0;
- }
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
- # Define outscreen (MSG,...) printf (MSG, _ va_args __)
- Int main (INT argc, char * argv [])
- {
- Outscreen ("Hello world! N % s "," _ this is a macro! N ");
- Return 0;
- }
Let's make a slight modification to the above Code and make it look like the following.
CPP Code
- # Define outscreen (MSG,...) printf (MSG, _ va_args __)
- Int main (INT argc, char * argv [])
- {
- Outscreen ("Hello world! ");
- Return 0;
- }