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

前端 未结 6 995
一生所求
一生所求 2021-01-30 09:01

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 -         


        
6条回答
  •  没有蜡笔的小新
    2021-01-30 09:33

    This one allows it to be used without #pragma (Microsoft specific I think) and when you click it takes you to the line since it shows the file and line number just like a regular err/warning message does since none of the other ones seem to do this. This used to work without the __pragma but newer versions of msvc require it. Ive been using it since sometime in the 90's. I use Visual Studio 2013

    #define MacroStr(x)   #x
    #define MacroStr2(x)  MacroStr(x)
    #define Message(desc) __pragma(message(__FILE__ "(" MacroStr2(__LINE__) ") :" #desc))
    

    example :

    Message("Need to add unit testing here")
    

    output: 1> c:\source\include\mithrilsoftware.h(180) :"Need to add unit testing here"

提交回复
热议问题