在预处理程序指令中使用变量

0 c c++ preprocessor-directive

哪个全局变量可以在预处理程序指令file.cpp中使用

int variable = 1;
#if variable >= 1
    int a = 0;
#else 
    int a = 1;
#endif
Run Code Online (Sandbox Code Playgroud)

要么

file.cpp

const int variable = 1;
#if variable >= 1
    int a = 0;
#else 
    int a = 1;
#endif
Run Code Online (Sandbox Code Playgroud)

或file.cpp

#include "header.h"
// extern in variable; in the header.h
#if variable >= 1
    int a = 0;
#else 
    int a = 1;
#endif
Run Code Online (Sandbox Code Playgroud)

使用proprocessor指令中的变量的规则是什么?如果一个可以折叠的变量,它可以用在#if /#elif#else指令中吗?

Lil*_*ard 10

对不起,你完全不能这样做.预处理器看不到变量.预处理器的核心是文本操纵器.它可以看到的唯一值是定义的#define,而不是变量.