The _Pragma Operator, Pragma Directives (#pragma)

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

C90 does not permit a #pragma directive to be produced as the result of a macro expansion.
However, the C99 
_Pragma operator enables you to embed a preprocessor macro in a pragma directive,
and 
_Pragma is permitted in C90 if --strict is 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

 

#pragmaDescription
#pragma align Aligns data items within structures.
#pragma alloca Provides an inline version of the functionalloca(size_t size).
#pragma altivec_vrsave This pragma is accepted and ignored.
#pragma chars Sets the sign type of character data.
#pragma comment Places a comment into the object file.
#pragma complexgcc Instructs the compiler how to pass parameters when calling complex math functions.
#pragma define Forces the definition of a template class without actually defining an object of the class.
#pragma disjoint Lists the identifiers that are not aliased to each other within the scope of their use.
#pragma enum Specifies the size of enum variables that follow.
#pragma execution_frequency Lets you mark program source code that you expect will be either very frequently or very infrequently executed.
#pragma hashome Informs the compiler that the specified class has a home module that will be specified by the IsHomepragma.
#pragma ibm snapshot 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 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 Controls the diagnostic messages generated by theinfo(...) compiler options.
#pragma ishome Informs the compiler that the specified class's home module is the current compilation unit.
#pragma isolated_call Lists functions that do not alter data objects visible at the time of the function call.
#pragma langlvl Selects the C or C++ language level for compilation.
#pragma leaves Takes a function name and specifies that the function never returns to the instruction after the function call.
#pragma map Tells the compiler that all references to an identifier are to be converted to a new name.
#pragma mc_func Lets you define a function containing a short sequence of machine instructions.
#pragma options Specifies options to the compiler in your source program.
#pragma option_override Specifies alternate optimization options for specific functions.
#pragma pack Modifies the current alignment rule for members of structures that follow this pragma.
#pragma priority Specifies the order in which static objects are to be initialized at run time.
#pragma reachable 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 Specifies those registers which value will be corrupted by the specified function. It must be used together with #pragma mc_func.
#pragma report Controls the generation of specific messages.
#pragma strings Sets storage type for strings.
#pragma unroll Unrolls inner loops in the program. This can help improve program performance.

 

 

 

posted @ 2013-06-05 13:14  IAmAProgrammer  阅读(836)  评论(0编辑  收藏  举报