There are three operators that are only available to preprocessor directives. These are the stringize, #, concatenation, ##, and charizing, #@, operators.
# Stringize Operator
Placing a single # in front of a macro parameter causes the compiler to insert the name of the argument instead of its value. This has the overall effect of converting the argument name into a string. The operator is necessary because parameters are not replaced if they occur inside string literals that are explicitly coded in a macro. The following example demonstrates the syntax for the stringize operator:
#define STRINGIZE(ivalue) printf(#ivalue “ is: %d”,ivalue) . . . int ivalue = 2; STRINGIZE(ivalue);
The output from the macro will appear as:
ivalue is: 2
## Concatenation Operator
The concatenation operator is useful when building variable and macro names dynamically. The operator concatenates the items, removing any white space on either side, forming a new token. When ## is used in a macro, it is processed after the macro parameters are substituted and before the macro is examined for any additional macro processing. For example, the following code shows how to create preprocessed variable names:
#define IVALUE_NAMES(icurrent_number) ivalue ## icurrent_number; . . . int IVALUE_NAMES(1);
The compiler sees the previous listing as the following declaration:
int ivalue1;
Notice that the preprocessor removed the blanks so that the compiler didn’t see ivalue1 as ivalue 1. The operator can be combined with other preprocessor directives to form complex definitions. The following example uses the concatenation operator to generate a macro name, which causes the preprocessor to invoke the appropriate macro:
#define MAKE_MACRO(n) MACRO ## n . . . MAKE_MACRO(1);
The output from the example will appear as:
MACRO1 invoked.
#@ Charizing Operator
The charizing preprocessor precedes formal parameters in a macro definition. This causes the actual argument to be treated as a single character with single quotation marks around it. For example: