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