12

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?

paleozogt
  • 6,393
  • 11
  • 51
  • 94

5 Answers5

17

About the closest equivalent would be #pragma message, or possibly #error (the latter stops compilation, the former just prints out the specified error message).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
14

Use #pragma message("Some message")

Jasper Bekkers
  • 6,711
  • 32
  • 46
8

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...)
Danny Parker
  • 1,713
  • 18
  • 30
0

#pragma WEIRD_VALUES_HERE

is the way I've always seen it done. M$ probably has the pragmas on their site somewhere.

Michael Dorgan
  • 12,453
  • 3
  • 31
  • 61
  • 3
    VS `#pragma` Reference: http://msdn.microsoft.com/en-us/library/d9x1s805%28v=VS.80%29.aspx – Nick T Apr 21 '10 at 18:46
0

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.

Michael Dorgan
  • 12,453
  • 3
  • 31
  • 61