C Macro Syntax
This document summarizes C language macro syntax.
1. Stringification Operator (#)
| |
THIS IS TEST CODEThe stringification operator (#) converts macro parameters to strings. It has the same effect as adding " ". [Code 1] shows an example where the THIS IS TEST CODE macro parameter is passed as a string to the printf() function.
2. Token Pasting Operator (##)
| |
i0 = 0The token pasting operator (##) combines separate tokens into one. In [Code 2], the INT_i() macro function is replaced with int i0 = 0, and the PRINT() macro function is replaced with printf("i%d = %d\n", 0, i0).
3. Variadic Macro
| |
| |
The 1999 C standard uses ... and __VA_ARGS__ to represent variadic arguments. [Code 3] shows the usage of variadic macros in the 1999 C standard syntax. GCC uses [name]... and [name] to represent variadic arguments. [Code 4] shows the usage of GCC variadic macros.