MSVC 中的宏扩展问题

Macro expansion problems in MSVC

我想知道为什么这个宏扩展了这么多。

#define CONCAT_IMPL(A, B) A##B
#define CONCAT(A, B) CONCAT_IMPL(A, B)

#define EAT(...)
#define TEST(ARG) EXPANDED, ARG) EAT(
#define GET_LAST(A, B) B

int result = 0;
result = GET_LAST(CONCAT(TEST, (1)), 2); // result is 2
result = GET_LAST(TEST(1), 2); // result is 2
result = GET_LAST(EXPANDED, 1) EAT(, 2); // result is 1

我想要GET_LAST(CONCAT(TEST, (1)), 2);评估值 1.

如果你能告诉我在 MSVC 上是否可行或者是否缺少某些内容,我将不胜感激。

C11 draft:

The sequence of preprocessing tokens bounded by the outside-most matching parentheses forms the list of arguments for the function-like macro. The individual arguments within the list are separated by comma preprocessing tokens, but comma preprocessing tokens between matching inner parentheses do not separate arguments.

GET_LAST(CONCAT(TEST, (1)), 2) 是使用包含两个参数的列表调用宏 GET_LAST。一个是 CONCAT(TEST, (1)),另一个是 2

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.

第一个参数A没有出现在宏的替换列表中,所以对相应的参数什么都不做。出现第二个参数B,所以对应的参数宏展开为2,替换列表中出现的B被替换为展开