【问题标题】:preprocessor #warning equivalent in Visual C++?Visual C++ 中的预处理器#warning 等价物?
【发布时间】:2015-06-24 00:22:43
【问题描述】:

在 C# 中,我们可以使用 #warning 在错误窗口中显示警告。
在 Visual C++ 中,#pragma message 类似,但它只是输出消息而不是警告。

在 C++(Windows、Visual Studio、MSVC)中,有没有办法故意向用户显示警告?

我试过#warning DEBUG is definedwhich works in some other compilers,但不是MSVC。
它给了我这个错误:

错误 C1021:无效的预处理器命令“警告”AecProject stdafx.h 49

【问题讨论】:

  • James McNellis 在这里为 MSVC 中的警告提供了出色的解决方案,捎带 #pragma message 并匹配编译器的内部标准化警告格式:stackoverflow.com/a/2706693/366904

标签: c++ visual-c++ c-preprocessor warnings


【解决方案1】:

在 gcc 中,#warning 以您期望的方式正常工作(即像 #error 它在编译时输出一条消息,但不会导致编译终止)

#warning 似乎在 Visual Studio 中不可用。相反,您可以尝试使用#pragma warning,尽管这不会发出消息,但允许更改编译器消息的设置。这个语法比较复杂,可以找到here

【讨论】:

  • 嗨,我收到了,但错误来自 boost/pending/relaxed_heap.hpp,并且该库正在内部使用我知道这不是你回答的问题,但如果你有答案。
猜你喜欢
  • 2020-11-09
  • 2014-08-02
  • 2012-09-20
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 2016-12-21
  • 2016-07-22
  • 1970-01-01
相关资源
最近更新 更多