Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 634
eonil Avatar asked Feb 08 '10 12:02

eonil


People also ask

What is preprocessor error in C?

#error is a preprocessor directive in C which is used to raise an error during compilation and terminate the process. Syntax: #error <error message> C. Usually, the error message is associated with preprocessor conditional statements like #if, #ifdef and others.

What is the error in the preprocessor?

A preprocessor error directive causes the preprocessor to generate an error message and causes the compilation to fail. The #error directive is often used in the #else portion of a #if – #elif – #else construct, as a safety check during compilation.

What is warning in C language?

Description. In the C Programming Language, the #warning directive is similar to an #error directive, but does not result in the cancellation of preprocessing. Information following the #warning directive is output as a message prior to preprocessing continuing.

What does ## mean in C preprocessor?

The double-number-sign or token-pasting operator (##), which is sometimes called the merging or combining operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token, and therefore, can't be the first or last token in the macro definition.


1 Answers

Place anywhere:

#ifndef DEBUG #error Only Debug builds are supported #endif 
like image 175
Hans Passant Avatar answered Sep 30 '22 10:09

Hans Passant