C preprocessor tokenization does not expand macro?

后端 未结 2 1084

1) Why is the macro MSG not expanded in the following expression?

#define MSG Hello
#define HELLO(name)  MSG ## name

void HELLO(Dave) () {}
<
2条回答
  •  臣服心动
    2021-01-04 21:41

    Because macro arguments are not substituted when preceded or followed by a ## operator.

    C11 §6.10.3.1 Argument substitution

    After the arguments for the invocation of a function-like macro have been identified, argument substitution takes place. A parameter in the replacement list, unless preceded by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is replaced by the corresponding argument after all macros contained therein have been expanded. Before being substituted, each argument’s preprocessing tokens are completely macro replaced as if they formed the rest of the preprocessing file; no other preprocessing tokens are available.

提交回复
热议问题