C中的#pragma和_Pragma()之间的区别 [英] Difference between #pragma and _Pragma() in C

查看:967
本文介绍了C中的#pragma和_Pragma()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C中#pragma_Pragma()有什么区别?

语法:

#pragma arg

_Pragma(arg)

我什么时候应该使用_Pragma(arg)?

推荐答案

_Pragma运算符已在C99中引入. _Pragma(arg)是运算符,与sizeofdefined很像,并且可以嵌入到宏中.

_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 single \ and 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆