How can I use #pragma message() so that the message points to the file(lineno)?

xtofl picture xtofl · May 11, 2011 · Viewed 49.7k times · Source

In order to add 'todo' items into my code, I want to put a message in the compiler output.
I would like it to look like this:

c:/temp/main.cpp(104): TODO - add code to implement this

in order to make use of the Visual Studio build output functionality to navigate to the respective line by double-clicking it.

But the __LINE__ macro seems to expand to an int, which disallows writing

#pragma message( __FILE__ "("__LINE__"): ..." )

Would there be another way?

Answer

RedX picture RedX · May 11, 2011

Here is one that allows you to click on the output pane:

(There are also some other nice tips there)

http://www.highprogrammer.com/alan/windev/visualstudio.html

 // Statements like:
 // #pragma message(Reminder "Fix this problem!")
 // Which will cause messages like:
 // C:\Source\Project\main.cpp(47): Reminder: Fix this problem!
 // to show up during compiles. Note that you can NOT use the
 // words "error" or "warning" in your reminders, since it will
 // make the IDE think it should abort execution. You can double
 // click on these messages and jump to the line in question.

 #define Stringize( L )     #L 
 #define MakeString( M, L ) M(L)
 #define $Line MakeString( Stringize, __LINE__ )
 #define Reminder __FILE__ "(" $Line ") : Reminder: "

Once defined, use like so:

#pragma message(Reminder "Fix this problem!") 

This will create output like:

C:\Source\Project\main.cpp(47): Reminder: Fix this problem!