IAbstract
IAbstract

Reputation: 19881

What does #pragma message do?

Using GCC on Linux (Mint)

I have a line of code ...

#pragma message "blah blah blah"

When I run GCC I get this output with no warning, errors, etc ...

src/source_file.c:29:9: note: ‘#pragma message: blah blah blah’
29 | #pragma message "blah blah blah"

enter image description here

I see tutorials specifying how to use #pragma message ... but I didn't know what to expect from compiler output.

Upvotes: -2

Views: 684

Answers (2)

user9706
user9706

Reputation:

Per 2 Diagnostic Pragmas:

GCC also offers a simple mechanism for printing messages during compilation.

 #pragma message string

Prints string as a compiler message on compilation. The message is informational only, and is neither a compilation warning nor an error. Newlines can be included in the string by using the ‘\n’ escape sequence.

Upvotes: 1

Maël
Maël

Reputation: 46

The #pragma is a preprocessor directive that provides additional information to the compiler. They are not part of the core language but allow for various compiler-specific customizations and optimizations. The correct syntax for #pragma message requires the message to be enclosed in parentheses and double quotes.

The pragma message can be used to output a message during compilation. For example if you write in the main.c file :

#pragma message("Compiling " __FILE__)

You should have this output :

Compiling main.c

Upvotes: 1

Related Questions