简体   繁体   English

预处理程序指令#error:'已定义DEBUG'

[英]Preprocessor directive #error: 'DEBUG is defined'

I have the first line in the file as: 我在文件中的第一行是:

#define DEBUG

In my program I have used this variable as: 在我的程序中,我将此变量用作:

    #region Preprocessor directives
    #if DEBUG
    #error DEBUG is defined
    #endif
    #endregion

I get this error upon compilation: #error: 'DEBUG is defined' . 编译时出现以下错误: #error:'已定义DEBUG'

Am I mistaking anything? 我有误会吗?

As I already pointed out in the comments, that is exactly what the `#error' preprocessor directive is intended to do. 正如我在评论中已经指出的那样,这正是“ #error”预处理程序指令的意图。 The description on MSDN says: MSDN上的说明说:

#error lets you generate an error from a specific location in your code. #error可让您从代码中的特定位置生成错误。

See here on MSDN: https://msdn.microsoft.com/en-us/library/x5hedts0.aspx 请参见MSDN上的此处: https : //msdn.microsoft.com/zh-cn/library/x5hedts0.aspx

So in your case your directive tells the preprocessor to show the error DEBUG is defined when the DEBUG symbol is set. 因此,在您的情况下,您的指令告诉预处理器显示错误, DEBUG is defined在设置DEBUG符号时DEBUG is definedDEBUG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM