2

Possible Duplicate:
Is there a portable way to print a message from the C preprocessor?

When navigating through a large code base, it is sometimes difficult to guess what is defined and what is not. Therefore, I want to print something at compilation time. For example:

#ifdef SOME_DEFINE
// I want a preprocessor to print something here so that 
//  I can know whether SOME_DEFINE is defined or not
#endif

Is this possible to do with C?
I saw something called #error somewhere. Maybe that is my only option, or not?

Community
  • 1
  • 1
pythonic
  • 20,589
  • 43
  • 136
  • 219
  • 4
    lots of questions about this already: http://stackoverflow.com/questions/3826832/is-there-a-portable-way-to-print-a-message-from-the-c-preprocessor – pb2q Jun 05 '12 at 18:03
  • 1
    Better than `#error` is `#warning`, if the preprocessor supports it. – Daniel Fischer Jun 05 '12 at 18:18

2 Answers2

1

For MS Visual C++:

#define __PRINT(str) __pragma(message(str))
Ruben
  • 2,488
  • 1
  • 18
  • 22
1

The great thing about the #error directive is that it works even if it is not supported!

If it's supported, the compiler tells you "error: #error" and if it is not supported, the compiler tells you "invalid preprocessing directive". Either way it's a fatal error and compilation stops, and the compiler tells you which was the offending line.

steveha
  • 74,789
  • 21
  • 92
  • 117