zoukankan      html  css  js  c++  java
  • 在VC程序中添加TODO、FIXME编译警告

    Many times you think much faster with your mind than with your fingers, so is good to put notes in code as if it were post-its, but that notes trends to end lost inside a big amount of lines of code.

    A good thing would be to be advised by the compiler output as if those notes were errors or warnings, so you can have a fast look to all the notes in code and direct acces to the file and line where those are.

    I do it using macros that use the #pragma message and __FILE__ __LINE__ preprocessor parameters. I have not tested with any other compiler, but it works in MSVC, and I suppose that message pragma is supported many other compilers.


    //---------------------------------------------------------------------------------------------
    // FIXMEs / TODOs / NOTE macros
    //---------------------------------------------------------------------------------------------
    #define _QUOTE(x) # x
    #define QUOTE(x) _QUOTE(x)
    #define __FILE__LINE__ __FILE__ "(" QUOTE(__LINE__) ") : "#define NOTE( x )  message( x )
    #define FILE_LINE  message( __FILE__LINE__ )#define TODO( x )  message( __FILE__LINE__"\n"           \
            " ------------------------------------------------\n" \
            "|  TODO :   " #x "\n" \
            " -------------------------------------------------\n" )
    #define FIXME( x )  message(  __FILE__LINE__"\n"           \
            " ------------------------------------------------\n" \
            "|  FIXME :  " #x "\n" \
            " -------------------------------------------------\n" )
    #define todo( x )  message( __FILE__LINE__" TODO :   " #x "\n" )
    #define fixme( x )  message( __FILE__LINE__" FIXME:   " #x "\n" )
    //---------------------------------------------------------------------------------------------
    // Example code
    //---------------------------------------------------------------------------------------------
    int main(int argc, char* argv[])
    {
     #pragma TODO(  We have still to do some work here... )
     #pragma FIXME( Limits are not controlled in that function or things like that )
     #pragma todo(  Have a look to flipcode daily ! )
     #pragma todo(  Sleep... )
     #pragma fixme( It seems that there is some leaks in that object )
     #pragma FILE_LINE   
     #pragma NOTE( " \n\
           A free format multiline, comment............\n\
                       So I can put a whole text here              \n\
          -------------------------------------------------")
     return 0;
    }
    //---------------------------------------------------------------------------------------------
     

    And that's the output for the example:


    Test.cpp
    c:\_code\kk\test.cpp(25) :
     ------------------------------------------------
    |  TODO :   We have still to do some work here...
     -------------------------------------------------
    c:\_code\kk\test.cpp(26) :
     ------------------------------------------------
    |  FIXME :  Limits are not controlled in that function or things like that
     -------------------------------------------------
    c:\_code\kk\test.cpp(28) :  TODO :   Have a look to flipcode daily !
    c:\_code\kk\test.cpp(29) :  TODO :   Sleep...
    c:\_code\kk\test.cpp(31) :  FIXME:   It seems that there is some leaks in that object
    c:\_code\kk\test.cpp(33) :        A free format multiline, comment............
                       So I can put a whole text here             
          -------------------------------------------------         
    Test.obj - 0 error(s), 0 warning(s)
     

    In an integrated IDE, you can click in the message line, and go directly to the file and line of code. You can use too the NOTE and FILE_LINE macros to create some free form comments.

    I think that it is a very good tip for people that are allways looking for a ZERO warnings code, because it makes easier to locate it and it's very usefull for common code of big and small projects with code in progress.

    Alberto Garcia-Baquero Vega ( wisefox@jet.es )
    Nebula Entertainment

  • 相关阅读:
    JD笔试试题(凭记忆写的+人生感悟 try finally )
    ZOJ 3626 Treasure Hunt I(树形dp)
    Oracle数据库有用函数
    leetcode
    BIEE11G系统数据源账号过期问题(默认安装步骤)
    class文件结构浅析(2)
    使用Lua 局部变量来优化性能,同一时候比較局部变量和全局变量
    Linux基本配置和管理 3 ---- Linux命令行文本处理工具
    android面试题及答案
    CentOS 6.4的安装--史上最全-CRPER木木
  • 原文地址:https://www.cnblogs.com/indif/p/2411614.html
Copyright © 2011-2022 走看看