小编Val*_*ouk的帖子

停止宏扩展

我对宏扩展延迟有疑问。这是一个例子:

#include <stdio.h>

#define CONST_ABC 15
#define CONST_5 7
#define ABC 5

#define PRINT(x) printf("CONST=%d\n", CONST_ ## x)

// The problematic macro
#define PRINT2(x) PRINT(x)

int main(int argc, char *argv[])
{
    PRINT(ABC); // Prints 15 - OK
    PRINT2(ABC); // Prints 7 - Not OK.
}
Run Code Online (Sandbox Code Playgroud)

如何定义PRINT2宏以使其使用PRINT且结果为 15?我越来越:

CONST=15
CONST=7
Run Code Online (Sandbox Code Playgroud)

并想得到:

CONST=15
CONST=15
Run Code Online (Sandbox Code Playgroud)

c c-preprocessor

5
推荐指数
1
解决办法
984
查看次数

标签 统计

c ×1

c-preprocessor ×1