Microsoft KB Archive/155196

= How to use the #pragma message to generate user-defined warning messages in Visual C++ =

Article ID: 155196

Article Last Modified on 6/2/2005

-

APPLIES TO


 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 1.51
 * Microsoft Visual C++ 1.52 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1
 * Microsoft Visual C++ 2.2
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q155196





SUMMARY
In some instances, you may find it advantageous to have the compiler generate user-defined warning messages such as the following:

collisions.cpp(1) : Warning Msg: Need to do 3-D collision checking

When such a warning is generated by the compiler and displayed in the Developer Studio's Output window, you can double-click on the warning message to get to the line of code with the message.



MORE INFORMATION
The following code illustrates how to use the #pragma message to force the compiler to generate the above warning message. Note the spacing around the colons in the third #define statement. The Visual Workbench that ships with the 16-bit versions of Visual C++ does not recognize a double-click in the Output window unless the proper spacing exists between the colons. // collisions.h
 * 1) define __STR2__(x) #x
 * 2) define __STR1__(x) __STR2__(x)
 * 3) define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "

// collisions.cpp
 * 1) pragma message(__LOC__"Need to do 3D collision testing")

