转自http://uw713doc.sco.com/en/SDK_cprog/_Preprocessing_Directives.html
Preprocessing directives
Preprocessing operators
The preprocessing operators are evaluated left to right, without any defined precedence.
- A macro parameter preceded by the # preprocessing operator has its corresponding unexpanded argument tokens converted into a string literal. (Any double quotes and backslashes contained in character constants or part of string literals are escaped by a backslash). The # character is sometimes referred to as the ``stringizing'' operator. This rule applies only within function-like macros.
- If a replacement token sequence contains a ## operator, the ## and any surrounding white space are deleted and adjacent tokens are concatenated, creating a new token. This occurs only when the macro is expanded. See ``Macro definition and expansion''
#
##
Macro definition and expansion
- An object-like macro is defined with a line of the form:
#define identifier token-sequence[opt]
where identifier will be replaced with token-sequence wherever identifier appears in regular text. - A function-like macro is defined with a line of the form:
#define identifier( identifier-list[opt] ) token-sequence[opt]
where the macro parameters are contained in the comma-separated identifier-list. The token-sequence following the identifier list determines the behavior of the macro, and is referred to as the replacement list. There can be no space between the identifier and the ( character. For example:#define FLM(a,b) a+b
The replacement-list a+b determines that the two parameters a and b will be added. - A function-like macro can also be defined with a line of the form:
#define identifier( identifier-list[opt], ... ) token-sequence[opt]
where if the identifier-list is not present, there is also no comma. This form of macro definition accepts zero or more arguments matching the ellipsis. Those arguments, if any, that match the ellipsis in an invocation of this macro replace the special identifier __VA_ARGS__ optionally present in the replacement token sequence. - A function-like macro is invoked in normal text by using its identifier, followed by a ( token, a list of token sequences separated by commas, and a ) token. For example:
FLM(3,2)
- The arguments in the invocation (comma-separated token sequences) may be expanded, and they then replace the corresponding parameters in the replacement token sequence of the macro definition. Macro arguments in the invocation are not expanded if they are operands of # or ## operators in the replacement string. Otherwise, expansion does take place. For example:
Assume that M1 is defined as 3:
#define M1 3
When the function-like macro FLM is used, use of the # or ## operators will affect expansion (and the result), as follows:
Definition Invocation Result Expansion? a+b FLM(M1,2) 3+2 Yes, Yes #a FLM(M1,2) "M1" No a##b FLM(M1,2) M12 No, No a+#a FLM(M1,2) 3+"M1" Yes, No In the last example line, the first a in a+#a is expanded, but the second a is not expanded because it is an operand of the # operator.
- The number of arguments in the invocation must match the number of parameters in the definition.
- A macro's definition, if any, can be eliminated with a line of the form:
#undef identifier
There is no effect if the definition doesn't exist.