Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preprocessor #warning equivalent in Visual C++?

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

like image 302
Nayana Adassuriya Avatar asked Apr 17 '15 08:04

Nayana Adassuriya


1 Answers

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

like image 111
Component 10 Avatar answered Sep 21 '22 12:09

Component 10