In some instances, you may find it advantageous to format your debug dump like:
filepathname.cpp(123) : something
When such a line is displayed in the Output window of your Developer Studio/Visual Studio, you can double-click on it, and jump to the location specified by the file path/line number pattern. It is very handy to generate debug dumps with easy access to the original line, so I wrote a macro to format debug dumps with the
I first found this feature of the build output window in the Knowledge Base article HOWTO: Use #pragma to Generate User-Defined Warning Messages, which is almost ideal to insert TODO blocks. Later I tried it in the debug output, and found it also existed in the debug output window. It may work in other output windows too.
The following code illustrates how to tell the compiler to format the debug dump with file path and line numbers:
#define TRACE_LINE(string) \
CString strTrace; \
strTrace.Format("%s(%d) : \t%ld:\t%s", \
if (strTrace.GetLength() > 512) \
TRACE("TRACE string too long !\r\n"); \
#define TRACE_LINE(string) void(0)
TRACE_LINE("Need to do 3D collision testing") ;
collisions.cpp.cpp(123) : Need to do 3D collision testing
I have other varieties of this such as
TRACE_LINE1 which takes a format string and a parameter, and
TRACE_LINE2 which takes a format string and two parameters, and so on. You can surely write yourself one without the MFC support also.
For additional information concerning the
__LINE__ predefined macros, see the Visual C++ Help file; Search on: "predefined macros", Topic: "Preprocessor Reference", and click on "ANSI".