In general, #pragma message (messagestring) is a text string (messagestring) sent to the standard Output window during compilation. A typical use method is to report and display information at compile time. The following code snippet is a message that is displayed in the standard Output window during compilation:
#if _m_ix86 = = 500
#pragma message ("Pentium processor Build")
#endif
Messagestring Ginsengnumber can extend a literal string constant to a macro that can display any form of characterString. For example, the following statement shows the name of the compiled file and the date and time when the file was last modified:
#pragma message ("compiling" __file__)
#pragma message ("Last modified on" __timestamp__)
#pragma message ("Remember to write some actual code in this sample app!!")
Let's use this feature to further extend the use of #pragma message. The following macro is defined first in a header file (assumed to be lfpragma.h):
#define PTODO_LINENUMBER_TO_STRING (x) #x
#define PTODO_LINENUMBER (x) ptodo_linenumber_to_string (x)
#define Include_file_and_line (String) __file__ "(" Ptodo_linenumber (__line__) "):" String
Then include the Lfpragma.h file in any CPP file, then we can refer to the previously defined macro as follows. Such as:
#pragma message (Include_file_and_line ("compiling") __file__)
#pragma message (Include_file_and_line ("Last Modified on") __timestamp__)
#pragma message (Include_file_and_line ("Remember to write some actual code in this sample app!!"))
What is the difference between using #pragma message and the usual method? Normally when we use #pragma message, we can see the output information of #pragma message in the standard Output window.However, the "Go to Error/tag" menu item in the context menu of the right mouse click popup is grayed out, not available. However, if you use the macro defined above, we can activate the "Go to Error/tag" in the context menu to navigate to the corresponding line of code
Pragma message is used to tell the programmer that the program is at compile time. And OUTPUTDEBUGSTR is the information that tells the programmer that the program is in the run time.
Here is an example of the pragma message.
cooperate with #if/#ifdef/#ifndefSet the prompt information at compile time, e.g.:
Test.cpp
#define UNICODE
#ifdef UNICODE
#pragma message ("Using the Unicode character set")
#else
#pragma message ("Use ANSI character set")
#endif
int main ()
{
return 0;
}
The role of #pragma message