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

  • 相关阅读:
    jcmd的简单实用
    ConfigMap介绍
    Okhttp3基本使用
    Spring中的@Transactional(rollbackFor = Exception.class)属性详解
    正则表达式中/i,/g,/ig,/gi,/m的区别和含义
    事务日志已满,原因为“ACTIVE_TRANSACTION”
    Windows Server查看和记录远程登录信息的方法
    Windows Server 2012无法安装 .NET3.5-安装角色或功能失败,找不到源文件
    将float转换为数据类型numeric时出现算术溢出错误
    java对redis的基本操作
  • 原文地址:https://www.cnblogs.com/indif/p/2411614.html
Copyright © 2011-2022 走看看