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

前端 未结 6 1094
一生所求
一生所求 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:27

    just whipped this up now, and it sure beats my old solution of using #error :D

    #define _STR(x) #x
    #define STR(x) _STR(x)
    #define TODO(x) __pragma(message("TODO: "_STR(x) " :: " __FILE__ "@" STR(__LINE__)))
    

    you can modify this how ever you like/to whatever suits your needs. An example of its usage:

    //in code somewhere
    TODO(Fix this);
    

    output in the console pane:

    1>TODO: Fix this :: c:\users\administrator\documents\visual studio 2008\projects\metatest\metatest\metatest.cpp@33
    

    only downside is you can't jump to the line of this (by double clicking the message in the console pane) using __pragma (but testing with #pragma it doesn't seem to be the case anyways...)

提交回复
热议问题