tags:

views:

158

answers:

4

As the title. I have a program must be compiled only in DEBUG mode. (testing purpose) So I want to prevent compilation in RELEASE mode by this way.

+9  A: 

Place anywhere:

#ifndef DEBUG
#error Only Debug builds are supported
#endif
Hans Passant
+1  A: 

If you simply want to report an error:

#ifdef RELEASE
  #error Release mode not allowed
#endif

will work with most compilers.

anon
+1  A: 

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
Laurent Etiemble
You didn't specify and `#pragma` statements. Your preprocessor directives are valid and portable.
Thomas Matthews
Sorry, I mix pragma and error while typing. Corrected in answer.
Laurent Etiemble
+2  A: 

C provide a #error statement, and most compilers add a #warning statement. It is recommended to quote the message.

philippe