更新:2007 年 11 月
错误消息
应为“defined(id)”
标识符必须出现在预处理器关键字之后的括号中。
也可能由于为 Visual Studio .NET 2003 进行的编译器一致性工作生成此错误:在预处理器指令中缺少括号。如果预处理器指令缺少右括号,则编译器将生成一个错误。
有关更多信息,请参见编译时的重大更改摘要。
示例
下面的示例生成 C2004:
// C2004.cpp
// compile with: /DDEBUG
#include <stdio.h>
int main()
{
#if defined(DEBUG // C2004
printf_s("DEBUG defined\n");
#endif
}
可能的解决方案:
// C2004b.cpp
// compile with: /DDEBUG
#include <stdio.h>
int main()
{
#if defined(DEBUG)
printf_s("DEBUG defined\n");
#endif
}