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

eonil picture eonil · Feb 8, 2010 · Viewed 56.1k times · Source

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?

Answer

Hans Passant picture Hans Passant · Feb 8, 2010

Place anywhere:

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