在VC程序中添加TODO、FIXME编译警告
2012-03-22 14:48
363 查看
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
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
相关文章推荐
- 如何在VC代码里添加TODO编译警告
- 如何在VC代码里添加TODO编译警告
- win8 vc++编译的程序在XP系统运行报错。一个警告标志(黄色三角形里面一个感叹号)
- 给VC程序添加版本号与编译时间
- 如何让VC在编译ARX项目时自动通知AutoCAD卸载ARX程序,并在编译完成后自动加载新编译的ARX程序
- 让VC编译出来的程序不依赖于msvcr80.dll/msvcr90.dll/msvcr100.dll等文件
- gcc编译含math.h程序的奇怪现象(并非未添加-lm)
- gcc程序编译时添加头文件和库文件时需注意的一个地方
- 在程序中获得驱动器盘符的方法,附源程序,可在VC7.1下编译运行
- 在VC中编译、运行程序的小知识点
- VC新版本编译的程序如何在老系统上运行
- vc2008编译的程序在其他电脑上无法运行的解决方案
- 用VC2013编译了一个程序,在Windows 8、Windows 7(64位、32位)下都能正常运行。但在Win XP,Win2003下运行时,却报错不能运行
- VC++ 利用MAPI实现在程序中调用默认的电子邮件程序发送EMAIL(可以添加附件)。
- 如何在VC中通过添加资源文件,使程序在Vista上用管理员权限运行
- VC中编译、运行程序的小知识点
- 关于 vc编译程序 脱离 vc环境运行的问题 (新手)
- 让VC编译出来的程序不依赖于msvcr80.dll/msvcr90.dll/msvcr100.dll等文件
- 预编译头文件(precompiled header)及VC编译程序时Cannot open precompiled header file: 'Debug/.pch': No such file or directory
- Linux程序编译时自动添加git或SVN版本