10

In C# we can use #warning to show a warning in error window.
In Visual C++, #pragma message is something like that, but it just a outputs a message not a warning.

In C++ (Windows, Visual Studio, MSVC) is there a way to show a warning to user purposely?

I tried #warning DEBUG is defined which works in some other compilers, but not MSVC.
It gives me this error:

error C1021: invalid preprocessor command 'warning' AecProject stdafx.h 49

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Nayana Adassuriya
  • 21,894
  • 22
  • 97
  • 139
  • James McNellis provides an excellent solution for warnings in MSVC here, piggybacking off of `#pragma message` and matching the compiler's internal standardized format for warnings: http://stackoverflow.com/a/2706693/366904 – Cody Gray Jul 05 '16 at 11:59

1 Answers1

9

In gcc, #warning works fine in the way that you would expect (i.e. like #error it outputs a message at compile time, but does not cause the compilation to terminate)

It seems that #warning is not available in Visual Studio. Instead you can try experimenting with #pragma warning although this does not emit a message but allows the settings for compiler messages to be altered. The syntax for this is more complex and can be found here

Component 10
  • 9,937
  • 5
  • 44
  • 62
  • Hi, I am getting this but the error is coming from boost/pending/relaxed_heap.hpp, and that library is being used internally I know this wasn't the question you answered but let me know if you have an answer. – anand_v.singh Feb 13 '20 at 05:48