#pragma message预编译指令使用技巧

转载自:https://blog.csdn.net/Tunix126/article/details/1521008

                                                                  #pragma message预编译指令使用技巧

一般情况下,#pragma message( messagestring )是在编译期间,将一个文字串(messagestring)发送到标准输出窗口。典型的使用方法是在编译时报告和显示信息。下面的代码段是编译期间在标准输出窗口显示一条消息:

#if _M_IX86 == 500
#pragma message( "Pentium processor build" )
#endif

messagestring 参数可以将文字串常量扩展成一个宏,从而可以显示任何形式的字符串。例如,下面的语句显示被编译文件的名字以及文件被最后一次修改的日期和时间:

#pragma message( "Compiling " __FILE__ ) 
#pragma message( "Last modified on " __TIMESTAMP__ ) 
#pragma message("Remember to write some actual code in this sample app!!"))

下面我们就利用这个特性,进一步扩展#pragma message的使用。先在一个头文件(假设为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

然后在任何cpp文件中包含lfpragma.h文件,那么我们就可以象下面这样引用前面定义的宏。如:

#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!!"))

这样使用#pragma message与通常使用的方法有什么不同呢?平常我们使用#pragma message时,在标准输出窗口中可以看见#pragma message的输出信息,但是鼠标点右键弹出的上下文菜单中“Go to Error/Tag”菜单项是置灰的,不可用。但是如果使用上面定义的宏,我们就可以激活上下文菜单中“Go to Error/Tag”,从而定位到相应的代码行。

如需要例子代码,请发邮件到 hangwire@sina.com 索取。
展开阅读全文

#pragma message 提示头文件被多次编译?

03-20

编译的时候rn[code=c]rn--------------------Configuration: petools - Win32 Release--------------------rnCompiling resources...rnCompiling...rnDisASM.cpprnNOTE: WINVER has been defined as 0x0500 or greater which enablesrnWindows NT 5.0 and Windows 98 features. When these headers were released,rnWindows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.rnFor this release when WINVER is defined as 0x0500 or greater, you can onlyrnbuild beta or test applications. To build a retail application,rnset WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdkrnto see if retail Windows NT 5.0 or Windows 98 headers are available.rnSee the SDK release notes for more information.rnExportDlg.cpprnFlcDlg.cpprnImportDlg.cpprnPEFile.cpprnpetools.cpprnNOTE: WINVER has been defined as 0x0500 or greater which enablesrnWindows NT 5.0 and Windows 98 features. When these headers were released,rnWindows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.rnFor this release when WINVER is defined as 0x0500 or greater, you can onlyrnbuild beta or test applications. To build a retail application,rnset WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdkrnto see if retail Windows NT 5.0 or Windows 98 headers are available.rnSee the SDK release notes for more information.rnpetoolsdlg.cpprnProesDlg.cpprn[/code]rnrn[color=#FF0000]搜索了下在windows.h中这样定义的[/color]rn[code=c]rnrn#if(WINVER >= 0x0500)rn#pragma message ("")rn#pragma message ("NOTE: WINVER has been defined as 0x0500 or greater which enables")rn#pragma message ("Windows NT 5.0 and Windows 98 features. When these headers were released,")rn#pragma message ("Windows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.")rn#pragma message ("")rn#pragma message ("For this release when WINVER is defined as 0x0500 or greater, you can only")rn#pragma message ("build beta or test applications. To build a retail application,")rn#pragma message ("set WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdk")rn#pragma message ("to see if retail Windows NT 5.0 or Windows 98 headers are available.")rn#pragma message ("")rn#pragma message ("See the SDK release notes for more information.")rn#pragma message ("")rn#endif[/code]rnrn我stdafx.h中定义了WINVER 0x0500. 似乎这不是问题的原因.rnwindows.h明明有#ifndef 这种防止多次编译, 为何build提示中还会出现两遍? 感谢. 论坛

预编译指令请教

10-08

在 某C文件中 有如下 代码:rnrn......rn/*--- End of included file: packet-goose-hf.c ---*/rn#line 50 "../../asn1/goose/packet-goose-template.c" [color=#FF0000] ----> 1[/color]rnrn/* Initialize the subtree pointers */rnstatic int ett_goose = -1;rnrnrn/*--- Included file: packet-goose-ett.c ---*/rn#line 1 "../../asn1/goose/packet-goose-ett.c" [color=#FF0000] -----> 2[/color]rnstatic gint ett_goose_GOOSEpdu = -1;rnstatic gint ett_goose_GSEMngtPdu = -1;rnstatic gint ett_goose_RequestResponse = -1;rnstatic gint ett_goose_GSEMngtRequests = -1;rnstatic gint ett_goose_GSEMngtResponses = -1;rnstatic gint ett_goose_GetReferenceRequestPdu = -1;rnstatic gint ett_goose_T_getReferenceRequestPDU_offset = -1;rnstatic gint ett_goose_GetElementRequestPdu = -1;rnstatic gint ett_goose_T_references = -1;rnstatic gint ett_goose_GSEMngtResponsePdu = -1;rnstatic gint ett_goose_PositiveNegative = -1;rnstatic gint ett_goose_T_responsePositive = -1;rnstatic gint ett_goose_SEQUENCE_OF_RequestResults = -1;rnstatic gint ett_goose_RequestResults = -1;rnstatic gint ett_goose_IECGoosePdu = -1;rnstatic gint ett_goose_SEQUENCE_OF_Data = -1;rnstatic gint ett_goose_Data = -1;rnrn/*--- End of included file: packet-goose-ett.c ---*/rn#line 55 "../../asn1/goose/packet-goose-template.c" [color=#FF0000]---------->3[/color]rnrn/*--- Included file: packet-goose-fn.c ---*/rn#line 1 "../../asn1/goose/packet-goose-fn.c" [color=#FF0000] ---------->4[/color]rn/*--- Cyclic dependencies ---*/rn.......rnrn以上与编译指令 到底是何意思?rn例如 标记1 处 ,是指 此处包含 packet-goose-template.c 的 第50行吗? 还是 从此处开始代表 packet-goose-template.c 的第 50行,即 源文件已改为 packet-goose-template.c ? 论坛

没有更多推荐了,返回首页