我有如下代码的一部分:
#define FEATURE_A 1
void function()
{
// some code
#ifdef FEATURE_A
// code to be executed when this feature is defined
#endif
// some code
}
该程序不执行#ifdef - #endif内的代码。但是当我将#ifdef更改为#ifndef并删除#define宏时,代码会被执行。下面的代码按预期工作。
//#define FEATURE_A 1
void function()
{
// some code
#ifndef FEATURE_A
// code to be executed when this feature is defined
#endif
// some code
}
谁能解释为什么在第一种情况下#ifdef - #endif中的代码没有执行,而在第二种情况下它可以工作?谁能告诉我什么设置可能是错误的?
不确定这是否重要,我使用的是 Visual Studio 2010。
提前致谢
更新: 当我清理并重新运行时,第二个也不起作用。它仅在编辑器中显示为启用的代码。
当我在 project->property->Configuration Properties-> c/c++ -> Preprocessor 中定义宏时,它们都工作正常。