Friday, August 9, 2013

Convenient way to place TODO into Visual Studio C++ project

Any ideas on the subject?

a. You can write a note on a sticker, put sticker on a wall in your office, then work from home for a couple of days and forget about your TODO.

b. You can write a note in your notebook, then add a couple of pages with other notes and forget your TODO.

c. You can file a Defect Request in ClearQuest (or other project management system) and be buried under bureaucracy process instead of coding. Probably your request would go to other developer and then he or she would do what your don't intend to do.

d. You can add a comment in code like with a small type (extra space or char):
//TODO:   mickhael, replace ch++ with  _tcsinc
then search for "TODO" with "Find-In-Files" and obtain tons of TODO's of the whole team.
Your may search "TODO: mikhael" and find nothing due to typo in the comment.

c. I'd recommend using of #pragma message:
#pragma message("//TODO:   mickhael, replace ch++ with  _tcsinc")  


this code will generate a message in Output window when compiling, poking you to perform an action:
1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>Compiling...
1>MyFile.cpp
1>
TODO:   mickhael, replace ch++ with  _tcsinc
The only inconvenience is that you cannot quickly get to the desired code by clicking on the message in the Output window, or by pressing F4. There is a solution, add these definitions into some misc.h file:
#define S(x) #x
#define S_(x) S(x)
#define S__LINE__ S_(__LINE__)
#define __FILEREF__ __FILE__ "(" S__LINE__ "): "
Definition of S__LINE__ got from: A: How to make preprocessor generate a string for __LINE__ keyword?

then add #pragma this way:
#include "misc.h"
...
#pragma message(
__FILEREF__ "//TODO:   mickhael, replace ch++ with  _tcsinc") 
and get your output:
1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>Compiling...
1>
MyFile.cpp
1>C:\MyProject\
MyFile.cpp(139): TODO:   mickhael, replace ch++ with  _tcsinc

No comments:

Post a Comment