"elif" 在 gcc 中:#elif 没有表达式错误

"elif" in gcc: #elif with no expression error

我正在尝试做这样的事情:

#define RELEASE_TEST

#if RELEASE
  // code1
#elif RELEASE_TEST
  // code2
#else
  // code3
#endif

gcc 关于 #elif 的声明:"error: #elif with no expression".

我不明白这个错误,因为我向"elif"提供了"RELEASE_TEST"表达式。

如何使我的代码正常工作?

RELEASE_TEST 已定义,但没有值,因此它扩展为 #elif,这是无效的。

您可以使用 #elif defined(RELEASE_TEST) 来测试它是否已定义,或者 #define RELEASE_TEST 1,这将导致该行扩展为 #elif 1