Reputation: 6573
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?
Upvotes: 12
Views: 14374
Reputation: 1773
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...)
Upvotes: 8
Reputation: 12515
Another thought is template style compile time asserts. Boost has a whole selection of these if you are wanting to check compile time code errors.
Upvotes: 0
Reputation: 490623
About the closest equivalent would be #pragma message
, or possibly #error
(the latter stops compilation, the former just prints out the specified error message).
Upvotes: 17
Reputation: 12515
#pragma WEIRD_VALUES_HERE
is the way I've always seen it done. M$ probably has the pragmas on their site somewhere.
Upvotes: 0