How do I generate an error or warning in the C preprocessor?

Viewed 73221

I have a program that must be compiled only in DEBUG mode. (testing purpose)

How can I have the preprocessor prevent compilation in RELEASE mode?

7 Answers

Place anywhere:

#ifndef DEBUG
#error Only Debug builds are supported
#endif

You can use a error directive for that. The following code will throw an error at compile time if DEBUG is not defined:

#ifndef DEBUG
#error This is an error message
#endif

If you simply want to report an error:

#ifdef RELEASE
  #error Release mode not allowed
#endif

will work with most compilers.

Related