Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#warning in Visual Studio

Tags:

c++

c

visual-c++

In gcc I can do compile-time warnings like this:

#if !defined(_SOME_FEATURE_)
   #warning _SOME_FEATURE_ not defined-- be careful!
#endif

But in Visual Studio this doesn't work. Is there an alternative syntax for #warning?

like image 411
paleozogt Avatar asked Apr 21 '10 18:04

paleozogt


2 Answers

Use #pragma message("Some message")

like image 189
Jasper Bekkers Avatar answered Oct 12 '22 00:10

Jasper Bekkers


There is a good article here on how to achieve a similar effect to #warning in visual studio:

http://goodliffe.blogspot.co.uk/2009/07/c-how-to-say-warning-to-visual-studio-c.html

Edit: Here is the relevant section from the above link, however I do recommend reading the article.

#define STRINGIZE_HELPER(x) #x
#define STRINGIZE(x) STRINGIZE_HELPER(x)
#define WARNING(desc) message(__FILE__ "(" STRINGIZE(__LINE__) ") : Warning: " #desc)

// usage:
#pragma WARNING(FIXME: Code removed because...)
like image 42
Danny Parker Avatar answered Oct 12 '22 02:10

Danny Parker