#pragma optimize是什么代码? [英] How portable is code with #pragma optimize?
问题描述
如何使用 #pragma optimize
?大多数编译器支持它,并且对此 #pragma
?
#pragma
是编译器添加非授权和非便携式 语言扩展 * 。
基本上,你永远不知道,至少有一个主要的C ++编译器is。
* :
从C ++标准(N3242):
16.6 Pragma指令 [cpp.pragma] >
以下形式的预处理指令:
#pragma
> pp-tokens opt new-line
导致实现以实现定义的方式运行。该行为可能导致翻译失败或导致翻译器或生成的程序以不合格的方式运行。
从C标准(委员会草案 - 2011年4月12日):
6.10.6 Pragma指令
语义
以下形式的预处理指令
#pragma
pp-tokens < sub> opt 新行
其中预处理标记
STDC
在
指令中(在任何宏替换之前)按pragma
174)使实现在
实现中定义方式。该行为可能导致翻译失败或导致
转换程序或结果程序以不合格的方式运行。任何不能被实现识别的
pragma
将被忽略。
下面是一个例子:
int main(){
#pragma omp parallel for
for(int i = 0; i <16; ++ i){}
}
C和C ++ OpenMP API的很大一部分实现为 #pragma
s。
How portable is code that uses #pragma optimize
? Do most compilers support it and how complete is the support for this #pragma
?
#pragma
is the sanctioned and portable way for compilers to add non-sanctioned and non-portable language extensions *.
Basically, you never know for sure, and at least one major C++ compiler (g++) does not support this pragma as is.
*:
From the C++ standard (N3242):
16.6 Pragma directive [cpp.pragma]
A preprocessing directive of the form
# pragma
pp-tokensopt new-linecauses the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner. Any pragma that is not recognized by the implementation is ignored.
From the C standard (Committee Draft — April 12, 2011):
6.10.6 Pragma directive
Semantics
A preprocessing directive of the form
# pragma
pp-tokensopt new-linewhere the preprocessing token
STDC
does not immediately followpragma
in the directive (prior to any macro replacement)174) causes the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner. Any suchpragma
that is not recognized by the implementation is ignored.
And here's an example:
int main () {
#pragma omp parallel for
for (int i=0; i<16; ++i) {}
}
A big part of the C and C++ OpenMP API is implemented as #pragma
s.
这篇关于#pragma optimize是什么代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!