C语言中#pragma和_Pragma()的区别 [英] Difference between #pragma and _Pragma() in C
问题描述
#pragma
和_Pragma()
在C语言中有什么区别?
What is the difference between #pragma
and _Pragma()
in C?
语法:
#pragma arg
和
_Pragma(arg)
什么时候应该使用 _Pragma(arg)
?
推荐答案
_Pragma
运算符在 C99
中引入._Pragma(arg)
是一个运算符,很像 sizeof
或 defined
,可以嵌入到宏中.
_Pragma
operator introduced in C99
. _Pragma(arg)
is an operator, much like sizeof
or defined
, and can be embedded in a macro.
根据 cpp.gnu.org 参考:
它的语法是_Pragma (string-literal)
,其中string-literal可以是普通的或宽字符的字符串文字.将所有 \
替换为单个 并将所有
"
替换为 "
. 然后处理结果,就好像它出现在 #pragma
指令的右侧一样.例如,
Its syntax is
_Pragma (string-literal)
, where string-literal can be either a normal or wide-character string literal. It is destringized, by replacing all\
with a singleand all
"
with a"
. The result is then processed as if it had appeared as the right hand side of a#pragma
directive. For example,
_Pragma ("GCC dependency "parse.y"")
与#pragma GCC dependency "parse.y"
效果相同.使用宏也可以达到同样的效果,例如
has the same effect as #pragma GCC dependency "parse.y"
.
The same effect could be achieved using macros, for example
#define DO_PRAGMA(x) _Pragma (#x)
DO_PRAGMA (GCC dependency "parse.y")
根据 IBM 教程:
_Pragma 运算符是指定#pragma 的另一种方法指令. 例如,以下两个语句是等价的:
The _Pragma operator is an alternative method of specifying #pragma directives. For example, the following two statements are equivalent:
#pragma comment(copyright, "IBM 2010")
_Pragma("comment(copyright, "IBM 2010")")
字符串 IBM 2010 被插入到 C++ 目标文件中,当编译如下代码:
The string IBM 2010 is inserted into the C++ object file when the following code is compiled:
_Pragma("comment(copyright, "IBM 2010")")
int main()
{
return 0;
}
有关_pragma 举个例子.
这篇关于C语言中#pragma和_Pragma()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!