Q155196: HOWTO: Use #pragma to Generate User-Defined Warning Messages
Article: Q155196
Product(s): Microsoft C Compiler
Version(s): WIN3X:1.5,1.51,1.52;WINNT:2.0,2.1,2.2,4.0,4.1,4.2,5.0
Operating System(s):
Keyword(s): kbide kbLangC kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC220 kbVC400 kbVC410 k
Last Modified: 04-AUG-2001
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual C++, versions 1.0, 1.5, 1.51, 1.52, 2.0, 2.1, 2.2, 4.0, 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition, versions 4.2, 5.0, 6.0
- Microsoft Visual C++, 32-bit Professional Edition, versions 4.2, 5.0, 6.0
- Microsoft Visual C++, 32-bit Learning Edition, version 6.0
-------------------------------------------------------------------------------
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
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "
// collisions.cpp
#pragma message(__LOC__"Need to do 3D collision testing")
REFERENCES
==========
For additional information concerning the #pragma message directive, see the
Visual C++ Help file; Search on: "message (pragma directive)."
For additional information concerning the __FILE__ and __LINE__ predefined
macros, see the Visual C++ Help file; Search on: "predefined macros," Topic:
"Preprocessor Reference," and click on "ANSI."
Additional query words:
======================================================================
Keywords : kbide kbLangC kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC220 kbVC400 kbVC410 kbVC420 kbVC500 kbVC600
Technology : kbVCsearch kbVC400 kbAudDeveloper kbvc150 kbvc100 kbVC220 kbVC410 kbVC420 kbVC500 kbVC600 kbVC151 kbVC200 kbVC210 kbVC32bitSearch kbVC152 kbVC500Search
Version : WIN3X:1.5,1.51,1.52;WINNT:2.0,2.1,2.2,4.0,4.1,4.2,5.0
Issue type : kbhowto
=============================================================================
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.