The C preprocessor offers four operators to help you in creating macros (see the section “The #define Directive”) and the #if series of directives.
The Macro Continuation Operator (\)
A macro usually must be contained on a single line. The macro continuation operator is used to continue a macro that is too long for a single line. When you are breaking a macro over several lines, use the macro continuation operator as the last character in the line to be continued. Here’s an example of a multiline macro:
#define PRINTMSG(operand) \
printf(#operand " = %d\n", operand)
This line is exactly equivalent to the following:
#define PRINTMSG(operand) printf(#operand " = %d\n", operand)
The macro continuation operator allows your macros to be read and formatted more easily. It doesn’t affect the operation of the macro.
The Stringize Operator (#)
The stringize operator is used in creating a macro. It takes the particular operand to the macro and converts it to a string. To see how this works, look at this example:
#define PRINTMSG(operand) printf(#operand " = %d\n", operand)
When an integer variable (nCount) is being used as a counter, for example, you might use the statement to display nCount’s value for debugging:
PRINTMSG(nCount + 1);
This statement then is expanded by the preprocessor to create the following source line:
printf("nCount + 1 " " = %d\n", nCount + 1);
This sample line of code shows that the variable’s name has been included (using string literal concatenation) as part of the format string that printf() uses.