0

Is it possible in any available C/C++ compiler to print messages from source file when I compile the source file (its okay if it doesn't print it while linking) . I will have to embed the message into the source file.

(To make it clearer, using a printf would print the message in run time. I do not want to print the message in run time.)

I am aware that the message can be put in a Makefile ( which is what I have been doing so far). However, I would really like if the message can be put in source file itself.

arbitUser1401
  • 575
  • 2
  • 8
  • 25
  • 4
    See http://stackoverflow.com/questions/3826832/is-there-a-portable-way-to-print-a-message-from-the-c-preprocessor – DrWatson Jun 15 '14 at 20:00
  • If your compiler supports it, you could use a `#warning` preprocessor directive, but bear in mind that the message will be displayed as a warning. – Filipe Gonçalves Jun 15 '14 at 20:00
  • Any particular C compiler? Have a look at #pragma message if it is Microsoft or gcc. Note that the syntax is different for MS and gcc – cup Jun 15 '14 at 20:07
  • Borland/CodeGear/Embarcadero compilers also support `#pragma message` – Remy Lebeau Jun 15 '14 at 20:08

2 Answers2

0

The C99 standard defines an #error preprocessor directive which can be used for this task:

§6.10.5:

A preprocessing directive of the form

#error pp-tokensopt new-line

causes the implementation to produce a diagnostic message that includes the specified sequence of preprocessing tokens.

Community
  • 1
  • 1
jwodder
  • 54,758
  • 12
  • 108
  • 124
0

Some compilers have #pragma message, which prints a user-defined message in the compiler's diagnostics output.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770