MSVC ++ how to output something to the "exit" -window at compile time

Sometimes I see that some projects write something in the output at compile time.

how can this be achieved in MSVC ++

thanks!

+2
source share
4 answers

use #pragma message for example.

 #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, like regular compiler messages

+13
source

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

 #pragma message("Hello World") 
+6
source

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

In addition, when a custom step is performed before or after assembly, the description field is reflected in the standard output.

+2
source

As Timo Grush said: the directive #pragma message used for this.

As an exotic side effect of template metaprogramming, it can also 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 an output message

 Line 10: error: aggregate 'Message<3628800> m' has incomplete type and cannot be defined 
+1
source

Source: https://habr.com/ru/post/886605/


All Articles