为什么 C++ 预处理器不能正确地对枚举值进行算术运算?

Why is the C++ preprocessor not doing arithmetic properly on enum values?

以下代码不会生成 #error,而是编译、运行并输出跟踪值 37(TT_LAST_PARM 等于 53,TT_FIRST_PARM 等于 16):

#if ((TT_LAST_PARM - TT_FIRST_PARM) >= 32)
#error More than 32 parm tokens
#else
HTRACE("%d", TT_LAST_PARM - TT_FIRST_PARM);
#endif

如果我对值进行硬编码,

#if ((53 - 16) >= 32)
#error More than 32 parm tokens
#else
    HTRACE("%d", 53 - 16);
#endif

预处理器确实产生了错误:

错误 1 ​​致命错误 C1189:#error:超过 32 个参数标记 d:\codeMTX\Knowbase\KBMatL\PrintParser.CPP 2663

enum 是 C/C++ 关键字,不是预处理器指令。
预处理器指令由前导 # 符号清楚地表示。

预处理器没有 have/know 一个叫做 TT_LAST_PARM 等的符号,并且根据 C++ 标准 (§16.1 ¶4):

After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers and keywords, except for true and false, are replaced with the pp-number 0

因此您的表达式计算结果为 (0 - 0) >= 32