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
2010-02-08 12:33:35
+1
A:
If you simply want to report an error:
#ifdef RELEASE
#error Release mode not allowed
#endif
will work with most compilers.
anon
2010-02-08 12:33:45
+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
2010-02-08 12:34:02
You didn't specify and `#pragma` statements. Your preprocessor directives are valid and portable.
Thomas Matthews
2010-02-08 22:55:18
Sorry, I mix pragma and error while typing. Corrected in answer.
Laurent Etiemble
2010-02-08 23:32:31
+2
A:
C provide a #error
statement, and most compilers add a #warning
statement. It is recommended to quote the message.
philippe
2010-02-08 12:37:07