2

sometimes i see that certain projects write something to the output during compilation.

how can that be achieved in MSVC++

thanks!

clamp
  • 33,000
  • 75
  • 203
  • 299

4 Answers4

13

use #pragma message e.g.

#define MESSAGE(t) message(__FILE__ "(" STRINGXXX(__LINE__) ") : " t)
#define STRINGXXX(x) STRINGYYY(x)
#define STRINGYYY(x) #x

then if you put

#pragma MESSAGE("TODO: testing")

it will appear as a clickable message just like the normal compiler messages

Steve Gilham
  • 11,237
  • 3
  • 31
  • 37
6

You want to include something like this in your source code:

#pragma message("Hello World")
Timo Geusch
  • 24,095
  • 5
  • 52
  • 70
2

You can use #pragma message in one of your source files to output a string when that file is preprocessed.

Also, when a custom, pre- or post- build step is executed, the "description" field is echoed to standard output.

Nick Meyer
  • 39,212
  • 14
  • 67
  • 75
1

As Timo Geusch said: the #pragma message directive is used for that.

As an exotic side effect of template metaprogramming, it's also possible to use the compiler as a calculator :)

template<int i> struct Message;

template<int i> struct Fac {
   static const int v = i * Fac< i-1 >::v; 
};

template<> struct Fac<1> { static const int v = 1; };

Message< Fac<10>::v > m;

will result in the output message

Line 10: error: aggregate 'Message<3628800> m' has incomplete type and cannot be defined
xtofl
  • 40,723
  • 12
  • 105
  • 192