The pragma Message Helper Macro

[Previous] [Next]

When I work on code, I often like to get something working immediately and then make it bulletproof later. To remind myself that some code needs additional attention, I used to include a line like this:

 #pragma message("Fix this later") 

When the compiler compiled this line, it output a string reminding me that I had some more work to do; however, this message was not that helpful. So I decided to find a way to make the compiler output the name of the source code file and the line number that the pragma appears on. If I have that information, not only do I know that I have additional work to do, but I immediately know the location of the surrounding code.

To output the source code file and the line number, you have to trick the pragma message directive by using a series of macros. I named the resulting macro chMSG, and it is used like this:

 #pragma chMSG(Fix this later) 

When this line is compiled, the compiler produces a line that looks like this:

 C:\CD\CmnHdr.h(82):Fix this later 

Using Microsoft Visual Studio, you can double-click on this line in the output window and be automatically positioned at the place in the file that requires additional attention.

Conveniently, the chMSG macro does not require that you use quotes around the text string.



Programming Server-Side Applications for Microsoft Windows 2000
Programming Server-Side Applications for Microsoft Windows 2000 (Microsoft Programming)
ISBN: 0735607532
EAN: 2147483647
Year: 2000
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net