The _Pragma Operator, Pragma Directives (#pragma)

#pragma directive : Specifies implementation-defined instructions to the compiler.

C90 does not permit a#pragmadirective to be produced as the result of a macro expansion.

However, the C99
_Pragmaoperator enables you to embed a preprocessor macro in a pragma directive,

and
_Pragmais permitted in C90 if--strictis not specified. For example:

# define RWDATA(X) PRAGMA(arm section rwdata=#X)
# define PRAGMA(X) _Pragma(#X)
RWDATA(foo)  // same as #pragma arm section rwdata="foo"
int y = 1;   // y is placed in section "foo"

_Pragma("directive") 其中directive是要满打满算的编译指令。_Pragma运算符允许编译指令参与宏替换。

_Pragma操作符

C99增加了_Pragma操作符,以便更灵活地利用pragma工具。在宏展开之后,下面这种形式的操作符表达式

_Pragma ("字符串常量")

的处理方式是把字符串常量的内容(在删除两边的双引号,并把字符串常量内部的\"替换为",把\替换为\之后)看成是#pragma指令中所出现的预处理器标记。

#pragma指令本身必须出现在同一行中,而且它的预处理器标记并不会执行宏展开,但_Pragma可以被其他表达式所包围,并且可以通过宏展开而产生。

_Pragma("STDC FENV_ACCESS ON") --> #pragma STDC FENV_ACCESS ON

_Pragma ( "align(power)" ) --> #pragma align(power)

General Purpose Pragmas

**#pragma** **Description**
[#pragma align](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgalin.htm#HDRRNPGALIN) Aligns data items within structures.
[#pragma alloca](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgalla.htm#HDRRNPGALLA) Provides an inline version of the function**alloca(size_t size)**.
[#pragma altivec_vrsave](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgaltv.htm#HDRRNPGALTV) This pragma is accepted and ignored.
[#pragma chars](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgchrs.htm#HDRRNPGCHRS) Sets the sign type of character data.
[#pragma comment](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgcmnt.htm#HDRRNPGCMNT) Places a comment into the object file.
[#pragma complexgcc](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgcplx.htm#HDRRNPGCPLX) Instructs the compiler how to pass parameters when calling complex math functions.
[#pragma define](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgdefn.htm#HDRRNPGDEFN) Forces the definition of a template class without actually defining an object of the class.
[#pragma disjoint](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgdsjt.htm#HDRRNPGDSJT) Lists the identifiers that are not aliased to each other within the scope of their use.
[#pragma enum](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgenum.htm#HDRRNPGENUM) Specifies the size of enum variables that follow.
[#pragma execution_frequency](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgexfq.htm#HDRRNPGEXFQ) Lets you mark program source code that you expect will be either very frequently or very infrequently executed.
[#pragma hashome](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpghaho.htm#HDRRNPGHAHO) Informs the compiler that the specified class has a home module that will be specified by the **IsHome**pragma.
[#pragma ibm snapshot](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgsnap.htm#HDRRNPGSNAP) Sets a debugging breakpoint at the point of the pragma, and defines a list of variables to examine when program execution reaches that point.
[#pragma implementation](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgimpl.htm#HDRRNPGIMPL) Tells the compiler the name of the file containing the function-template definitions that correspond to the template declarations in the include file which contains the pragma.
[#pragma info](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpginfo.htm#HDRRNPGINFO) Controls the diagnostic messages generated by the**info(...)** compiler options.
[#pragma ishome](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgisho.htm#HDRRNPGISHO) Informs the compiler that the specified class's home module is the current compilation unit.
[#pragma isolated_call](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgisoc.htm#HDRRNPGISOC) Lists functions that do not alter data objects visible at the time of the function call.
[#pragma langlvl](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpglang.htm#HDRRNPGLANG) Selects the C or C++ language level for compilation.
[#pragma leaves](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpglves.htm#HDRRNPGLVES) Takes a function name and specifies that the function never returns to the instruction after the function call.
[#pragma map](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgmap1.htm#HDRRNPGMAP1) Tells the compiler that all references to an identifier are to be converted to a new name.
[#pragma mc_func](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgmcfn.htm#HDRRNPGMCFN) Lets you define a function containing a short sequence of machine instructions.
[#pragma options](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgoptn.htm#HDRRNPGOPTN) Specifies options to the compiler in your source program.
[#pragma option_override](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgoovr.htm#HDRRNPGOOVR) Specifies alternate optimization options for specific functions.
[#pragma pack](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgpack.htm#HDRRNPGPACK) Modifies the current alignment rule for members of structures that follow this pragma.
[#pragma priority](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgprio.htm#HDRRNPGPRIO) Specifies the order in which static objects are to be initialized at run time.
[#pragma reachable](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgrchb.htm#HDRRNPGRCHB) Declares that the point after the call to a routine marked reachable can be the target of a branch from some unknown location.
[#pragma reg_killed_by](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgregk.htm#HDRRNPGREGK) Specifies those registers which value will be corrupted by the specified function. It must be used together with **#pragma mc_func**.
[#pragma report](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgrept.htm#HDRRNPGREPT) Controls the generation of specific messages.
[#pragma strings](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgstrg.htm#HDRRNPGSTRG) Sets storage type for strings.
[#pragma unroll](http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/compiler/ref/rnpgunrl.htm#HDRRNPGUNRL) Unrolls inner loops in the program. This can help improve program performance.

原文链接: https://www.cnblogs.com/shangdawei/archive/2013/06/05/3118743.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/91310

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月10日 上午1:07
下一篇 2023年2月10日 上午1:07

相关推荐