Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a portable way to print a message from the C preprocessor?

People also ask

What is C preprocessor output?

Preprocessing is a stage where preprocessor directives are expanded or processed before source code is sent to the compiler. The most common example of such directive is #include or #define. A preprocessor output has “. i” extension.

What is the output of C program with preprocessor directives?

9) What is the output of C program with preprocessor directives.? Explanation: You can define a constant using Preprocessor directive even inside a main() function or any other function. So CVV is replaced by 199 everywhere it appears.

What is #pragma message?

A typical use of the message pragma is to display informational messages at compile time. The message-string parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination.


The warning directive is probably the closest you'll get, but it's not entirely platform-independent:

#warning "C Preprocessor got here!"

AFAIK this works on most compilers except MSVC, on which you'll have to use a pragma directive:

#pragma message ( "C Preprocessor got here!" )

The following are supported by MSVC, and GCC.

#pragma message("stuff")
#pragma message "stuff"

Clang has begun adding support recently, see here for more.


You might want to try: #pragma message("Hello World!")


Most C compilers will recognize a #warning directive, so

 #warning "Got here"

There's also the standard '#error' directive,

 #error "Got here"

While all compilers support that, it'll also stop the compilation/preprocessing.