search    
Hewlett-Packard
Pragma Directives and Attributes
Use a #pragma directive to control the actions of the compiler in a particular portion of a translation unit without affecting the translation unit as a whole.

Put pragmas in your C/C++ source code where you want them to take effect. Unless otherwise noted below, a pragma is in effect from the point where it is included until the end of the translation unit or until another pragma changes its status.


Note:
  • A #pragma directive is an instruction to the compiler and is ignored during preprocessing.
  • Block-scoped pragmas must appear before the first statement or declaration of the block.
  • Except for C99 "STDC" pragmas are case insensitive.
  • Pragma overrides the command-line option if the two are not in agreement, when a command-line option and pragma are used together.
  • The references to the aCC command also apply to the cc, c89, or c99 command.

This section discusses the following topics:
Pragma Syntax
#pragma pragma-string

pragma-string can be one of the following instructions to the compiler with any required parameters:

  • ALIGN - Support for user specified alignment of global data
  • assert - Support for condition testing
  • BINDING - Specify a blanket binding
  • COPYRIGHT - Specify a copyright string
  • COPYRIGHT_DATE - Specify a copyright date for the copyright string
  • DEFAULT_BINDING - Symbols are assigned the default export class
  • diag_xxx - Specify diagnostic error reporting
  • ESTIMATED_FREQUENCY - Specify execution frequency
  • EXTERN - Inlining of import stubs for calls to default export class symbols
  • FINI - Specify a termination function
  • FLOAT_TRAPS_ON - Specify floating-point trap handling
  • FREQUENTLY_CALLED - Identify frequently called functions
  • HDR_STOP - Stop precompiling headers
  • HIDDEN - Symbols are assigned the hidden export class
  • HP_DEFINED_EXTERNAL - Inline import stubs
  • HP_DEFINED_INTERNAL - Inline import stubs
  • IF_CONVERT - Specify If-Conversion for a block
  • INIT - Specify an initialization function
  • [NO]INLINE - Enables/disables inlining
  • IVDEP - Ignores loop dependencies involving references to array-typed entities
  • LOCALITY - Name a code subspace
  • LOCALITY_ALL - Name a code subspace
  • NODEPCHK - Ignores all loop dependencies
  • NO_INLINE - Enables/disables inlining
  • NO_RETURN - Hint to optimizer that the named functions never return
  • OMP ATOMIC - Updates memory location atomically
  • OMP BARRIER - Synchronizes all threads
  • OMP CRITICAL - Restricts the execution of structured block to one thread at a time
  • OMP FLUSH - Specifies a cross-thread sequence to ensure all the threads have a consistent view
  • OMP MASTER - Instructs the structured block following to be executed by master thread
  • OMP PARALLEL - Defines a region that is executed by multiple threads is parallel
  • OMP PARALLEL FOR - Shortcut for a parallel region that contains a single for pragma
  • OMP PARALLEL SECTIONS - Shortcut for specifying a parallel region containing a single sections pragma
  • OMP SECTIONS - Specifies a set of constructs to be divided among threads
  • OMP SINGLE - Specifies the associated structured block is executed by only one thread
  • OMP THREADPRIVATE - Provides file-scope variables local to a thread
  • OPTIMIZE - Turn optimization on or off
  • OPT_LEVEL - Set an optimization level
  • PACK - Allows maximum alignment of class fields having non-class types
  • POP - Retrieves a pragma off of the pragma stack
  • PROTECTED - Symbols are assigned the protected export class
  • PTRS_STRONGLY_TYPED -Use strict pointer type testing
  • [NO]PTRS_TO_GLOBALS - Tells optimizer if pointers are used to access "name"
  • PUSH - Places a pragma on the pragma stack
  • RARELY_CALLED - Identify rarely called functions
  • STDC CX_LIMITED_RANGE - Limits mathematical range
  • STDC FP_CONTRACT - Allows contract optimizations
  • STDC FENV_ACCESS - Access floating point environment flags
  • UNALIGN - Support misaligned data access for both PA and Itanium®-based aCC
  • UNROLL_FACTOR - Specifies the unroll factor
  • VERSIONID - Specify a version string

Initialization and Termination Pragmas
This section describes the INIT and FINI pragmas. These pragmas allow the user to set up functions which are called when a load module (a shared library or executable) is loaded (initializer) or unloaded (terminator).

For example, when a program begins execution, its initializers get called before any other user code gets called. This allows some set up work to take place. In addition, when the user’s program ends, the terminators can do some clean up. When a shared library is loaded or unloaded, its initializers and terminators are also executed at the appropriate time.


INIT Pragma

#pragma INIT string

Use #pragma INIT to specify an initialization function. The function takes no arguments and returns nothing. The function specified by the INIT pragma is called before the program starts or when a shared library is loaded.

Example:

#pragma INIT "my_init"
void my_init() { ... do some initializations ... }


FINI Pragma

#pragma FINI "string"

Use #pragma FINI to specify a termination function. The function specified by the FINI pragma is called after the program terminates by either calling the libc exit() function, returning from the main() or _start() functions, or when the shared library, which contains the FINI is unloaded from memory. Like the function called by the INIT pragma, the termination function takes no arguments and returns nothing.

Example:

#pragma FINI "my_fini"
void my_fini() { ... do some clean up ... }

Copyright Notice and Identification Pragmas
The following pragmas can be used to insert strings in code.
COPYRIGHT Pragma

#pragma COPYRIGHT "string"

string is a set of characters included in the copyright message in the object file. COPYRIGHT pragma specifies a string to include in the copyright message and puts the copyright message into the object file.

If no date is specified (using pragma COPYRIGHT_DATE), the current year is used in the copyright message.

For example, assuming the year is 1999, the directive

#pragma COPYRIGHT "Acme Software"

places the following string in the object code:

(C) Copyright Acme Software, 1999. All rights reserved. No part of this program may be photocopied, reproduced, or transmitted without prior written consent of Acme Software.

The following pragmas

#pragma COPYRIGHT_DATE "1990-1999"

#pragma COPYRIGHT "Brand X Software"

place the following string in the object code:

(C) Copyright Brand X Software, 1990-1999. All rights reserved. No part of this program may be photocopied, reproduced, or transmitted without prior written consent of Brand X Software.


IVDEP

#pragma IVDEP

for the associated loop, this pragma directs the compiler to ignore any apparent loop dependencies involving references to array-typed entities.


LOCALITY Pragma

#pragma LOCALITY "string"

string specifies a name to be used for a code section.

The LOCALITY pragma specifies a name to be associated with the code written to a relocatable object module. The string is forced to be upper case in C. All code following the LOCALITY pragma is associated with the name specified in string. Code that is not headed by a LOCALITY pragma is associated with the name .text.

The smallest scope of a unique LOCALITY pragma is a function. For example, the directive,

#pragma LOCALITY "MINE"

builds the name .text.MINE and associates all code following this pragma with this name, unless another LOCALITY pragma is encountered.


LOCALITY_ALL Pragma

#pragma LOCALITY_ALL string

The LOCALITY_ALL pragma specifies a name to be associated with the linker procedures and global variables that should be grouped together at program binding or load time. These are written to a relocatable object module. All procedures and global variables following the LOCALITY_ALL pragma are associated with the name specified in the string.


VERSIONID Pragma

#pragma VERSIONID "string"

string is a string of characters that HP aC++ places in the object file.

The VERSIONID pragma specifies a version string to be associated with a particular piece of code. The string is placed into the object file produced when the code is compiled.

For example, the directive

#pragma VERSIONID "Software Product, Version 12345.A.01.05"

places the following characters into the object file.

Software Product, Version 12345.A.01.05

Data Alignment Pragmas
This section discusses the following data alignment pragmas and their various arguments available on the HP-UX systems to control alignment across platforms.


ALIGN Pragma

#pragma align N

N is a number raised to the power of 2.

HP aC++ supports user specified alignment for global data. The pragma takes effect on next declaration. If the align pragma declaration is not in the global scope or if it is not a data declaration, the compiler displays a warning message. If the specified alignment is less than the original alignment of data, a warning message is displayed, and the pragma is ignored. Note that for C code you must initialize the variables, otherwise the compiler will generate a warning.

Example:

#pragma align 2
char c; // "c" is at least aligned on 2 byte boundary.
#pragma align 64
int i, a[10]; // "i" and array "a" are at least aligned 64 byte boundary.
      // the size of "a" is still 10*sizeof(int)

PACK Pragma

#pragma PACK [n|[push|pop]|[, <name>][, n]|show]

n can be 1, 2, 4, 8, or 16 bytes. If n is not specified, maximum alignment is set to the default value.

This file-scoped pragma allows you to specify the maximum alignment of class fields having non-class types. The alignment of the whole class is then computed as usual, to the alignment of the most aligned field in the class.


Note: The result of applying #pragma pack n to constructs other than class definitions (including struct definitions) is undefined and not supported.

Example:

struct S1 {
char c1;  // Offset 0, 3 bytes padding
int i;    // Offset 4, no padding
char c2;  // Offset 8, 3 bytes padding
};  // sizeof(S1)==12, alignment 4

#pragma pack 1

struct S2 {
char c1;  // Offset 0, no padding
int i;    // Offset 1, no padding
char c2;  // Offset 5, no padding
};  // sizeof(S2)==6, alignment 1

// S3 and S4 show that the pragma does not affect class fields
// unless the class itself was defined under the pragma.
struct S3 {
char c1;  // Offset 0, no padding
S1 s;     // Offset 1, no padding
char c2;  // Offset 13, no padding
};  // sizeof(S3)==14, alignment 1

struct S4 {
char c1;  // Offset 0, no padding
S2 s;     // Offset 1, no padding
char c2;  // Offset 7, no padding
};  // sizeof(S4)==8, alignment 1

#pragma pack

struct S5 {  // Same as S1
char c1;  // Offset 0, 3 bytes padding
int i;    // Offset 4, no padding
char c2;  // Offset 8, 3 bytes padding
};  // sizeof(S5)==12, alignment 4

#pragma pack (push, my_new_align, 1)
struct S6 {  // Same as S2
char c1;  // Offset 0, no padding
int i;    // Offset 1, no padding
char c2;  // Offset 5, no padding
};  // sizeof(S6)==6, alignment 1

#pragma pack 2
#pragma pack show // compiler diagnostic
                   // that shows current
                   // pragma pack setting
struct S7 {
char c1; // Offset 0, 1 byte padding
int i;   // Offset 2, no padding
char c2; // Offset 6, 1 byte padding
};  // sizeof(S7)==8, alignment 2

#pragma pack (pop, my_new_align)
struct S8 {  // Same as S1
char c1;  // Offset 0, 3 bytes padding
int i;    // Offset 4, no padding
char c2;  // Offset 8, 3 bytes padding
};  // sizeof(S8)==12, alignment 4

The pack pragma may be useful when porting code between different architectures where data type alignment and storage differences are of concern. Refer to the following examples:


Basic Example
The following example illustrates the pack pragma and shows that it has no effect on class fields unless the class itself was defined under the pragma.
struct S1 {
char c1;  // Offset 0, 3 bytes padding
int i;    // Offset 4, no padding
char c2;  // Offset 8, 3 bytes padding
};  // sizeof(S1)==12, alignment 4

#pragma pack 1

struct S2 {
char c1;  // Offset 0, no padding
int i;    // Offset 1, no padding
char c2;  // Offset 5, no padding
};  // sizeof(S2)==6, alignment 1

// S3 and S4 show that the pragma does not affect class fields
// unless the class itself was defined under the pragma.
struct S3 {
char c1;  // Offset 0, 3 bytes padding
S1 s;     // Offset 4, no padding
char c2;  // Offset 16, 3 bytes padding
};  // sizeof(S3)==20, alignment 4

struct S4 {
char c1;  // Offset 0, no padding
S2 s;     // Offset 1, no padding
char c2;  // Offset 7, no padding
};  // sizeof(S4)==8, alignment 1

#pragma pack

struct S5 {  // Same as S1
char c1;  // Offset 0, 3 bytes padding
int i;    // Offset 4, no padding
char c2;  // Offset 8, 3 bytes padding
};  // sizeof(S5)==12, alignment 4



Template Example
If the pragma is applied to a class template, every instantiation of that class is influenced by the pragma value in effect when the template was defined.


Note: The alignment of specializations and partial specializations of templates is undefined and unsupported if either the primary template or the specialization is under the influence of a #pragma pack directive.
#pragma pack 1

template<class T>
struct ST1 {
char c1;
T x;
char c2;
};

#pragma pack

ST1<int> obj;      // Same layout as S2 in the prior example

template <>        // Explicit specialization
struct ST1<void> {
char c1;
char c2;
};                       // Undefined (unsupported) behavior
		 // ST1 was defined under a #pragma pack 1
		 // directive.



Handling Unaligned Data
Direct access to unaligned class fields is handled automatically by HP aC++. However, this results in slower access times than for aligned data. Indirect access (through pointers and references) to unaligned class fields is also handled automatically.
Note: If you take the address of a data field and assign it to a pointer, it is not handled automatically and is likely to result in premature termination of the program if not handled appropriately.

Example:

#include <stdio.h>
#pragma pack 1
struct S1 {
char c1;
int i;
char c2;
};

#pragma pack
int main() {
S1 s;
S1 *p = &s;
printf("%d\n", s.i);   // OK
printf("%d\n", p->i);  // OK
int *ip = &p->i;       // Undefined behavior
			// Likely Abort unless compiled with +u1
			// The address of a reference (*ip) is
			// assigned to an int pointer.
printf("%d\n", *ip);
}
To enable indirect access to unaligned data that has been assigned to another type, use the following:
  • Link in the library -lunalign and arm the appropriate signal handler with a call to allow_unaligned_data_access(). This causes every signal due to unaligned access to be intercepted and handled as expected. It also creates significant run-time overhead for every access to unaligned data, but does not impact access to aligned data.

Implicit Access to Unaligned Data
Calls to non-static member functions require that an implicit this pointer be passed to these functions, which can then indirectly access data through this implicit parameter. If such an access is to unaligned data, the situation in the prior example occurs.

Furthermore, virtual function calls often require indirect access to a hidden field of a class that could be unaligned under the influence of the #pragma pack directive.

If passing the address of a field to other code, consider the following example. Unless compiled with -DRECOVER on the command line and linked with -lunalign, the following example is likely to prematurely terminate with a bus error.

Example:

#include <stdio.h>
#ifdef RECOVER
extern "C" void allow_unaligned_data_access();
#endif

#pragma pack 1

struct PS1 {
PS1();
~PS1();
private:
char c;
int a;
};

#pragma pack

PS1::PS1(): a(1) {   // There appears to be no pointer, but there
	     // is an unaligned access, possibly through "this."
printf("In constructor.\n");
}

PS1::~PS1() {
a = 0;           // Misaligned access, possibly though "this"
printf("In destructor.\n");
}

int main() {
#if defined(RECOVER)
allow_unaligned_data_access();
#endif
PS1 s;
}



UNALIGN Pragma

#pragma unalign [1|2|4|8|16]
typedef T1 T2;

T1 and T2 have the same size and layout, but with specified alignment requirements.

The unalign pragma can be applied with typedef to define a type with special alignment. The unalign pragma takes effect only on next declaration.

If the unalign pragma declaration is not in the global scope or if it is not a typedef, compiler displays a warning message. If the specified alignment is greater than the original alignment of the declaration, then an error message is displayed, and the pragma is ignored.

Example:

#pragma unalign 1 
typedef int ua_int;            // ua_int is of int type with 1 byte alignment

typedef ua_int *ua_intPtr;     // this typedef is not affected by above 
		       // unalign pragma, it defines a pointer type
		       // which points to 1 byte aligned int

The interaction between pack and unalign pragmas is as follows:
#pragma pack 1
struct S {
char c;
int i;
};
#pragma pack 0

S s;
ua_int *ua_ip = &s.i;         // ua_ip points to 1 byte aligned int 
*ua_ip = 2;                   // mis-aligned access to 1 byte aligned int 


Note:The HP_ALIGN pragma, which is supported by HP ANSI C compiler, is not supported by aCC. The pack and unalign pragmas can replace most of the HP_ALIGN functionality.
Optimization Pragmas
The following optimization pragmas are supported in HP aC++:
OPTIMIZE Pragma

#pragma OPTIMIZE ON
#pragma OPTIMIZE OFF

This pragma is used to toggle optimization on/off for different sections of source code as these pragmas are encountered in a top to bottom read of a source file.


Note: You must specify one of the optimization level options on the aCC command, otherwise this pragma is ignored. This pragma cannot be used within a function.
Example:
aCC +O2 prog.C

#pragma OPTIMIZE OFF
void A(){    // Turn off optimization
...      // for this function
}

#pragma OPTIMIZE ON
void B(){    // Restore optimization
...      // to level 2.
}


OPT_LEVEL Pragma

#pragma OPT_LEVEL 0
#pragma OPT_LEVEL 1
#pragma OPT_LEVEL 2
#pragma OPT_LEVEL 3
#pragma OPT_LEVEL 4

The OPT_LEVEL pragma sets the optimization level to 0, 1, 2, 3, or 4.


Note: You must specify one of the optimization level options on the aCC command, otherwise this pragma is ignored. This pragma cannot raise the optimization level above the level specified in the command line. This pragma cannot be used within a function.
Example:
aCC -O prog.C

#pragma OPT_LEVEL 1
void A(){      // Optimize this function at level 1.
...
}
#pragma OPT_LEVEL 2
void B(){      // Restore optimization to level 2.
...
}

FLOAT_TRAPS_ON Pragma

#pragma FLOAT_TRAPS_ON [function {,function}]


Note: This pragma is not supported in C++. It is deprecated for HP C and C++ C-mode. You should use: #pragma STDC FENV_ACCESS ON instead.
The #pragma FLOAT_TRAPS_ON directive informs the compiler that the function(s) may enable floating-point trap handling. When the compiler is so informed, it will not perform loop invariant code motion (LICM) on floating-point operations in the function(s) named in the pragma.

This pragma is required for proper code generation when floating-point traps are enabled.

Example:

#pragma FLOAT_TRAPS_ON xyz,abc

This pragma directive informs the compiler and optimizer that xyz and abc have floating-point traps turned on and therefore LICM optimization should not be performed. A dummy name _ALL represents all functions.


[NO]INLINE Pragma

#pragma [NO]INLINE sym[, sym]

The [NO]INLINE pragma enables[disables] inlining for all functions or specified functionname(s).

Example:

To specify inlining of the two subprograms checkstat and getinput, use:

#pragma INLINE checkstat, getinput

To specify that an infrequently called routine should not be inlined when compiling at optimization level 3 or 4, use:

#pragma NOINLINE opendb


Note: This pragma is supported in legacy HP C and C++ C-mode only.

NODEPCHK Pragma

#pragma NODEPCHK

For the associated loop, this pragma directs the compiler to ignore all loop dependencies (regardless of type) except for induction variables and some other scalar loop dependencies as determined by the compiler implementation.


NO_INLINE Pragma

#pragma NO_INLINE

This is a synonym for #pragma NOINLINE. The NO_INLINE pragma disables inlining for all functions or specified function name(s).


NO_RETURN Pragma

#pragma NO_RETURN function1, [function2, . . .]

The NO_RETURN pragma is an optimizer assertion for named functions to never return to the call site. This allows the optimizer to delete any code after the function. A C++ function marked with the NO_RETURN pragma may still throw an exception unless it has an empty throw list.

 

Diagnostic Pragmas


diag_xxx Pragmas
#pragma diag_suppress message1 message2 ...
#pragma diag_warning message1 message2 ...
#pragma diag_error message1 message2 ...
#pragma diag_default message1 message2 ...

Command line options help you to generate diagnostic messages for the entire build or for a specific source file. The diag pragmas let you manage warnings for a specific region within a source file. The use of #pragma diag_suppress within the source code disables generation of warning N after the pragma in the source file. The pragma diag_default restores the default handling for the diagnostic message N. Similarly, diag_warning enables generation of a diagnostic message and diag_error converts a warning to an error.

Only diagnostics above 2000 are affected. This pragma will not affect the lower numbered diagnostics issued by the compiler's driver program.

Refer to the HP Code Advisor documentation for additional information.


Note: These pragmas are supported only on the HP Integrity systems.


The following example disables warning #2549-D locally:

      int i;
      #pragma diag_suppress 2549
      printf ("i = %d\n", i);
      #pragma diag_default 2549
Other Pragmas
The following is a list of other pragmas in HP aC++:
assert Pragma

      #pragma assert non-zero(constant-expression) "string" 

When the compiler encounters this directive, it evaluates the expression. If the expression is zero, the compiler generates a message that contains the specified string and the compile time constant expression.

For example:

     #pragma assert non_zero(sizeof(a) == 12) "a is the wrong size"

In this example, if the compiler determines that sizeof a is not 12, the following diagnostic message is output:

     "foo.c", line 10: error #2020: The assertion "(sizeof(a) == 12)"  was not true.

a is the wrong size.

Consider the following example that verifies both the size of a struct and the offset of one of its elements:

      #include <stddef.h>
     typedef struct {
        int a;
        int b;
     } s;
     #pragma assert non_zero(sizeof(s) == 8) "sizeof assert failed"
     #pragma assert non_zero(offsetof(s,b) == 4) "offsetof assert failed"

This pragma provides a similar behavior to that of the Tru64 C compiler.


BINDING Pragma

#pragma BINDING {hidden|protected|extern|default}

Global symbols that follow this pragma will be given a specific binding. Command line options and binding pragmas referring to specific symbols (ex. #pragma hidden symbol) override this pragma. This pragma will override command line bindings that do not refer to a specific symbol (ex. -Bprotectedd).


DEFAULT_BINDING Pragma

#pragma DEFAULT_BINDING [symbol{,symbol}]

Global symbols are assigned the default export class. These symbols may be imported or exported outside of the current load module. The compiler will access tentative and undefined symbols through the linkage table. Any symbol that is not assigned to another export class through use of another pragma (or -B option or the deprecated +O[no]extern option) will have the default export class.


ESTIMATED_FREQUENCY Pragma

#pragma ESTIMATED_FREQUENCY f

This block-scoped pragma allows you to tell the compiler your estimate of how frequently the current block is executed as compared to the immediately surrounding block. You can indicate the average trip count in the body of a for loop or the fraction of time a then clause is executed. Frequency, f can be expressed as a floating-point or integer constant. The compiler accepts preprocessor expressions that evaluate to a compile time constant.


EXTERN Pragma

#pragma EXTERN [symbol{,symbol}]

The specified symbols, or all undefined symbols if no list is provided, are assigned to the default export class. Additionally, the compiler will inline the import stub for calls to these symbols. No compile time binding of these symbols will be done. All references to these symbols will be through the linkage table, so an unnecessary performance penalty will occur if extern is applied to a listed symbol that is resolved in the same load module. This is the pragma equivalent of -Bextern and is global in scope.


FREQUENTLY_CALLED Pragma

#pragma FREQUENTLY_CALLED [symbol{,symbol}]

This file-scoped pragma identifies functions that are frequently called within the application. The pragma must be placed prior to any definition of or reference to the named function. If not, the behavior is undefined. FREQUENTLY_CALLED pragma is independent of +Oprofile=use in that it overrides any dynamically obtained profile information.


HDR_STOP Pragma

#pragma HDR_STOP

This pragma instructs the compiler to stop precompiling headers.


HIDDEN Pragma

#pragma HIDDEN [symbol{,symbol}]

The specified symbols, or all symbols (if no symbols are specified), are assigned the hidden export class. The hidden export class is similar to the protected export class. These symbols will not be preempted by symbols from other load modules, so the compiler may bypass the linkage table for both code and data references and bind them to locally defined code and data symbols.

In addition, hidden symbols will not be exported outside the current load module. The linker may eliminate them from a shared library, but in an executable, they remain accessible to the debugger unless -Oprocelim is also specified. This is the pragma equivalent of -Bhidden and is global in scope.


HP_DEFINED_EXTERNAL Pragma

#pragma HP_DEFINED_EXTERNAL name1[,name2,...nameN]

The specified symbols, or all undefined symbols (if no list is provided), are assigned to the default export class. Additionally, the compiler will inline the import stub for calls to these symbols. No compile time binding of these symbols will be done. All references to these symbols will be through the linkage table, so an unnecessary performance penalty will occur if extern is applied to a listed symbol that is resolved in the same load module. This is the pragma equivalent of the -Bextern option and is global in scope. This pragma is equivalent to the #pragma EXTERN.


HP_DEFINED_INTERNAL Pragma

#pragma HP_DEFINED_INTERNAL name1[,name2,...nameN]

The specified symbols, or all symbols (if no symbols are specified), are assigned the protected export class. That means these symbols will not be preempted by symbols from other load modules, so the compiler may bypass the linkage table for both code and data references and bind them to locally defined code and data symbols. This pragma is equivalent to the -Bprotected option and is global in scope. This pragma is equivalent to #pragma PROTECTED.


IF_CONVERT Pragma

#pragma IF_CONVERT

This block-scoped pragma instructs the compiler to If-Convert the current scope. There is no command-line option equivalent. If-Conversion is a compiler process that eliminates conditional branches by the use of predicates. The compiler is instructed to If-Convert all non-loop control flow nested within the current block. Without this pragma, the compiler would employ its own heuristics to determine whether to perform If-Conversion. With this pragma, If-Conversion is always performed. If-Convert can be specified in a loop containing conditional branches other than the loop-back branch. This makes it more likely the compiler will modulo schedule the loop, as loops containing conditional branches are more difficult to modulo schedule. The pragma can also be used for non-looping constructs.


POP Pragma

#pragma POP

The last pushed pragma is removed from the pragma stack and state is restored. The binding state reverts to the binding state prior to the last "push". This pragma can only be used with the blanket binding pragmas.


PROTECTED Pragma

#pragma PROTECTED [symbol{,symbol}]

The specified symbols, or all symbols (if no symbols are specified), are assigned the PROTECTED export class. That means these symbols will not be preempted by symbols from other load modules, so the compiler may bypass the linkage table for both code and data references and bind them to locally defined code and data symbols. This pragma is equivalent to the -Bprotected option and is global in scope.


PTRS_STRONGLY_TYPED Pragma

#pragma [NO]PTRS_STRONGLY_TYPED {BEGIN | END}

This pragma turns strong pointer type testing on and off. When turned on (BEGIN) if a pointer typing error is detected, it will generate a warning if the typing error can be safely ignored. If the typing error cannot be safely ignored, it will generate a warning and flag the compilation appropriately, or if this is not possible, it will generate an error. This feature is disabled using the END attribute.


[NO]PTRS_TO_GLOBALS Pragma

#pragma [NO]PTRS_TO_GLOBALS name

This pragma aids alias analysis. It must be specified at global scope and immediately precede the declaration of the variable or entry named. The pragma tells the optimizer whether the global variable or entry "name" is accessed [is not accessed] through pointers. If NOPTRS_TO_GOBALS is specified, it is assumed that statically-allocated data (including file-scoped globals, file scoped statics, and function-scoped static variables) will not be read or written through pointers. The default is PTRS_TO_GLOBALS.


PUSH Pragma

#pragma PUSH pragma_name

This pragma will save the current state on the pragma stack for the named pragma. All subsequent uses of the named binding pragma will be reverted when the "pop" is encountered. Note that this pragma can only be used with the blanket binding pragmas.


RARELY_CALLED Pragma

#pragma RARELY_CALLED [symbol{,symbol}]

This file-scoped pragma identifies functions that are rarely called within the application. The pragma must be placed prior to any definition of or reference to the named function. If not, the behavior is undefined. RARELY_CALLED pragma is independent of +Oprofile=use option. It overrides any dynamically obtained profile information.


STDC CX_LIMITED_RANGE Pragma

#pragma STDC CX_LIMITED_RANGE ON
#pragma STDC CX_LIMITED_RANGE OFF

This pragma enables limited range mathematical behavior for specific blocks of code. Note that, this pragma applies to complex arithmetic only. (See ISO/IEC 9899 Standard for more information.)

This pragma can occur outside an external declaration or within a compound statement. When outside external declarations, the pragma takes effect from its occurrence until another STDC CX_LIMITED_RANGE pragma is encountered or until the end of the translation unit. When within a compound statement, the pragma takes effect from its occurrence until another STDC CX_LIMITED_RANGE pragma is encountered within a nested compound statement, or until the end of the compound statement. If this pragma is used in any other context, the behavior is undefined. The default state is OFF.


STDC FP_CONTRACT Pragma

#pragma STDC FP_CONTRACT ON
#pragma STDC FP_CONTRACT OFF

This pragma tells the compiler whether or not it is permitted to contract expressions. See ISO/IEC 9899 Standard for more information.

Each pragma can occur either outside external declarations or preceding all explicit declarations and statements inside a compound statement. When outside external declarations, the pragma takes effect from its occurrence until another FP_CONTRACT pragma is encountered, or until the end of the translation unit. When inside a compound statement, the pragma takes effect from its occurrence until another FP_CONTRACT pragma is encountered within a nested compound statement, or until the end of the compound statement. At the end of a compound statement, the state for the pragma is restored to its condition before the compound statement.

If this pragma is used in any other context, the behavior is undefined. The default state is ON.


STDC FENV_ACCESS Pragma

#pragma STDC FENV_ACCESS ON
#pragma STDC FENV_ACCESS OFF

This pragma provides a means to inform the compiler when a program might access the floating point environment to test flags or run under non-default modes. Use of the pragma allows certain optimizations that could subvert flag tests and mode changes such as global common sub expression elimination, code motion, and constant folding.

The pragma can be placed either outside external declarations or preceding all explicit declarations and statements inside a compound statement. When outside external declarations, the pragma takes effect from its occurrence until another FENV_ACCESS pragma is encountered or until the end of the translation unit. When inside a compound statement, the pragma is in effect from its occurrence until another FENV_ACCESS pragma is encountered within the nested compound statement or until the end of the compound statement. At the end of a compound statement, the state for the pragma is restored to its condition just before the compound statement.

If the pragma is used in any other context, the behavior is undefined. If part of a program tests flags or runs under non-default mode settings but was translated with the state for the FENV_ACCESS pragma off, then the behavior of the program is undefined.

See ISO/IEC 9899 Standard for more information.


UNROLL_FACTOR Pragma

#pragma UNROLL_FACTOR n
#pragma UNROLL n
#pragma UNROLL (n)

This block-scoped pragma applies the unroll factor to loops contained in the current block. You can apply an unroll factor which you think is best for the given loop or apply no unroll factor to the loop. If this pragma is not specified, the compiler uses its own heuristics to determine the best unroll factor for the inner loop.

A user specified unroll factor will override the default unroll factor applied by the compiler.

Specifying n=1 will prevent the compiler from unrolling the loop. Specifying n=0 allows the compiler to use its own heuristics to apply the unroll factor.


Note: The UNROLL_FACTOR pragma will be ignored if it is placed in a loop other than the innermost loop. The UNROLL pragma must be immediately followed by a loop statement and will be ignored if it is not an innermost loop.

OMP ATOMIC Pragma

#pragma omp atomic
expression-stmt

where expression stmt must have one of the following forms:

  • x binop = expr
  • x++
  • ++x
  • x--
  • --x
Here, x is an lvalue expression with scalar type and expr is an expression with scalar type that does not reference the object designated by x. The atomic directive ensures that a specific memory location is updated atomically, rather than exposing it to the possibility of multiple, simultaneous writing threads.


OMP BARRIER Pragma

#pragma omp barrier

The barrier pragma synchronizes all the threads in a team. When encountered, each thread waits until all the threads in the team have reached that point.

The smallest statement to contain a barrier must be a block or a compound statement. barrier is valid only inside a parallel region and outside the scope of for, section, sections, critical, ordered, and master.


OMP CRITICAL Pragma

#pragma omp critical [(name)]
structured-block

The critical pragma identifies a construct that restricts the execution of the associated structured block to one thread at a time.

The name parameter is optional. All unnamed critical sections map to the same name.


OMP FOR Pragma

#pragma omp for [clause1,clause2, ...]
for-loop

[clause1, clause2, ...] indicates that the clauses are optional. There can be zero or more clauses.

clause may be one of the following:

  • private(list)
  • firstprivate(list)
  • lastprivate(list)
  • ordered
  • schedule(kind[,chunksize])
  • nowait
See OpenMP Clauses for more information.


OMP FLUSH Pragma

#pragma omp flush [(list)]

(list) names the variables that will be synchronized.

The flush pragma, whether explicit or implied, specifies a cross-thread sequence point at which the implementation is required to ensure that all the threads in a team have a consistent view of certain objects in the memory.

A flush directive without a list is implied for the following directives:

  • barrier
  • an entry to and exit from critical
  • at entry to and exit from ordered
  • at entry to and exit from parallel
  • at entry to and exit from parallel for
  • at entry to and exit from parallel sections
  • at exit from single
  • at exit from for
  • at exit from sections

Note: The directive is not implied if a nowait clause is present.


OMP MASTER Pragma

#pragma omp master
structured-block

The master pragma directs that the structured block following it should be executed by the master thread (thread 0) of the team. Other threads in the team do not execute the associated block.


OMP ORDERED Pragma

#pragma omp ordered
structured-block

The ordered pragma indicates that the following structured-block should be executed in the same order in which iterations will be executed in a sequential loop.

An ordered directive must be within the dynamic extent of a for or a parallel for construct that has an ordered clause. When the ordered clause is used with schedule which has a chunksize, then the chunksize is ignored by the compiler.


OMP PARALLEL Pragma

#pragma omp parallel [clause1, clause2,...]
structured-block

[clause1, clause2, ...] indicates that the clauses are optional. There can be zero or more clauses. clause can be one or more of the following:

  • private(list)
  • firstprivate(list)
  • default(shared|none)
  • shared(list)
  • reduction(op:list)
  • if(scalar-expression)
  • copyin(list)
  • num_threads
The parallel pragma defines a parallel region, which is a region of the program that is executed by multiple threads in parallel. This is the fundamental construct that starts parallel execution.

See OpenMP Clauses for more information.


OMP PARALLEL FOR Pragma

#pragma omp parallel for [clause1, clause2, ... ]
for-loop

[clause1, clause2, ...] indicates that the clauses are optional.

There can be zero or more clauses. The parallel for pragma is a shortcut for a parallel region that contains a single for pragma.

parallel for admits all the allowable clauses of the parallel pragma and the for pragma except for the nowait clause.


OMP PARALLEL SECTIONS Pragma

#pragma omp parallel sections [clause1, clause2, ...]
{
[#pragma omp section ]
structured-block
[#pragma omp section
structured-block ]
. . .
}

[clause1, clause2, ...] indicates that the clauses are optional. There can be zero or more clauses. The parallel sections pragma is a shortcut for specifying a parallel clause containing a single sections pragma.

parallel sections admits all the allowable clauses of the parallel pragma and the sections pragma except for the nowait clause.


OMP SECTIONS Pragma

#pragma omp sections [clause1, clause2, ...]
{
#pragma omp section
[ structured-block ]
[#pragma omp section
structured-block ]
. . .
}

[clause1, clause2, ...] indicates that the clauses are optional. There can be zero or more clauses. clause may be one of the following:

  • private(list)
  • firstprivate(list)
  • lastprivate(list)
  • reduction(op:list)
  • nowait
The section or sections pragmas identify a construct that specifies a set of constructs to be divided among threads in a team. Each section is executed by one of the threads in the team.

See OpenMP Clauses for more information.


OMP SINGLE Pragma

#pragma omp single [clause1, clause2, . . .]
[ structured-block ]

[clause1, clause2, ...] indicates that the clauses are optional. There can be zero or more clauses.

clause may be one of the following:

  • private(list)
  • firstprivate(list)
  • copyprivate(list)
  • nowait
The single directive identifies a construct that specifies the associated structured block that is executed by only one thread in the team (not necessarily the master thread).

See OpenMP Clauses for more information.


OMP THREADPRIVATE Pragma

#pragma omp threadprivate (list)

(list) is a comma-separated list of variables that do not have an incomplete type. The threadprivate directive makes the named file-scope, namescope-scope, or static block-scope variables private to a thread.

OpenMP Clauses
Clauses on directives may be repeated as needed, subject to the restrictions listed in the description of each clause. The order in which clauses appear in directives is not significant. If variable-list appears in a clause, it must specify only variables.

The following is the list of clauses in OpenMP directives:


private

private(list)

The private clause declares the variables in the list to be private to each thread in a team. A new object with automatic storage duration is allocated within the associated structured block for each thread in the team.


firstprivate

firstprivate(list)

The firstprivate clause provides a superset of the functionality provided by the private clause. Variables specified in the list have private clause semantics described earlier. The new private object is initialized, as if there is an implied declaration inside the structured block and the initializer is the value of the original object.


lastprivate

lastprivate(list)

When lastprivate clause is specified in a loop or section, the value of the lastprivate variable from either the sequentially last iteration of the associated loop, or the lexically last section directive is assigned to the variable's original object. The lastprivate clause provides a superset of the functionality provided by the private clause. Variables specified in the list have private clause semantics described earlier.


copyprivate

copyprivate(list)

The copyprivate clause can be used to broadcast values acquired by a single thread directly to all instances of the private variables in the other threads.


Note: The copyprivate clause can only appear on the single directive.

if

if(scalar-expression)

The associated block of code will be executed in parallel if the scalar-expression evaluates to a non-zero value. Otherwise no parallelization happens and it is executed sequentially.

Example:

#pragma omp parallel private(x) if (a>b) reduction(+:p)
{
// code to be parallelized only when a is greater than b
}


default

default(shared|none)

Specifying default(shared) clause is equivalent to explicitly listing each currently visible variable in a shared clause unless it is threadprivate or const-qualified.

A variable referenced in the scope of default(none) should be explicitly qualified by a private or shared clause.


shared

shared(list)

The shared clause causes the variables that appear in the list to be shared among all threads in a team. All threads within a team access the same storage area for the shared variables


copyin

copyin(list)

The copyin clause copies the value of master thread's copy of a threadprivate variable to all other threads at the beginning of the parallel region. This clause can only be used with the parallel directive.


reduction

reduction(op:list)

The reduction clause performs a reduction on the scalar variables that appear in the list, with the operator op.


nowait

nowait

The nowait clause removes the implicit barrier synchronization at the end of a for or sections construct.


ordered

ordered

The ordered clause must be present when ordered directives bind to the for construct.


schedule

schedule(kind[,chunksize])

The schedule clause specifies how iterations of the for loop are divided among threads of the team.

The kind of schedule can be any of:

  • static
  • dynamic
  • guided
  • runtime
chunksize should be a loop invariant integer expression.


num_threads

num_threads(integer-expression)

The num_threads clause allows a user to request a specific number of threads for a parallel construct. If the num_threads clause is present, then the value of integer-expression is the number of threads requested.

Attributes
__attribute__ is a language feature that allows you to add attributes. The capabilities are similar to those of #pragma. It is more integrated into the language syntax than pragmas and its placement in the source code depends on the construct to which the attribute is being applied.

The attributes supported are:


attribute aligned

__attribute__ aligned (alignment)

This attribute specifies the minimum alignment for a variable or structure field, measured in bytes. For example, the declaration:

      int x __attribute__ ((aligned (16))) = 0;

causes the compiler to allocate the global variable x on a 16-byte boundary.

You can also specify the alignment of structure fields. For example,

      struct foo { int x[2] __attribute__ ((aligned (128)));}

causes the compiler to allocate the field member "x" to be aligned on a 128 byte boundary.

The maximum alignment that can be specified is 128. This feature is for compatibility with gcc.


attribute malloc

__attribute__ ((malloc))

The malloc The malloc attribute is used to improve optimization by telling the compiler that:

  1. The return value of a call to such a function points to a memory location or can be a null pointer.
  2. On return of such a call (before the return value is assigned to another variable in the caller), the memory location mentioned in 1. can be referenced only through the function return value; e.g., if the pointer value is saved into another global variable in the call, the function is not qualified for the malloc attribute.
  3. The lifetime of the memory location returned by such a function is defined as the period of program execution between a) the point at which the call returns and b) the point at which the memory pointer is passed to the corresponding deallocation function. Within the lifetime of the memory object, no other calls to malloc routines should return the address of the same object or any address pointing into that object.

Many wrappers around malloc() obey these rules. (The compiler already knows that malloc() itself obeys these rules.)

Example:

      void *foo(int i) __attribute__ ((malloc));


attribute non_exposing

__attribute__ ((non_exposing))

Example:

      void foo(int *pi) __attribute__ ((non_exposing));

The non_exposing attribute is used to improve optimization by telling the compiler that this function does not cause any address it can _derive_ from any of its formal parameters to become visible after a call to the function returns.

An address becomes visible if the function returns a value from which it can be _directly derived_ or if the function stores it in a memory location that is visible (can be referenced directly or indirectly) after the call to the function returns.

(Note that there is no such thing as a formal parameter of array type. A formal parameter declared to be of type "array of T" is treated as being of type "pointer to T"; and when an actual argument is of type "array of T", a pointer to the first element of that array is passed.)

Many wrappers around free() obey these rules. (The compiler already knows that free() itself obeys these rules.) Many functions that have nothing to do with memory allocation also obey these rules.

For the purposes of the specification above, the definitions of the terms _directly derived_ and _derived_ are as follows:

The addresses that can be _directly derived_ from some value V are the following:

  • If V is or can be converted to a pointer value (except by a C++ user-defined conversion), then consider P to be a pointer object containing that value. The value of any expression _based on_ P (as defined in C99) can be _directly derived_ from V. For example, if P is a pointer object containing the value V, then "P", "&P->f", "&P[i]", and "P+j" are expressions based on P, and thus their values are _directly derived_ from V.
  • If V is an array, then any addresses that can be _directly derived_ from V's elements can be _directly derived_ from V.
  • If V is a class, struct, or union, then any addresses that can be _directly derived_ from V's nonstatic data members can be _directly derived_ from V.
  • If V is a reference, then &V can be _directly derived_ from V.
The addresses that can be _derived_ from some value V are the addresses that can be _directly derived_ from V and the addresses that can be _derived_ from the result of dereferencing those addresses. The function does not store addresses passed to it as arguments to any memory location that is visible (can be referenced directly or indirectly) after the call to this function returns.


attribute noreturn

__attribute__ ((noreturn))

Example:

     void foo(int i) __attribute__ ((noreturn));
Similar to the NO_RETURN pragma, this attribute asserts to the optimizer that this function never returns to the call site. This allows the optimizer to delete any code after the function call. A C++ function marked with this attribute may still throw an exception unless it has an empty throw list.
attribute format

__attribute__ ((format(type, arg_format_string, arg_check_start)))

Example:

int foo(int i, const char *my_format, ...) __attribute__ ((format(printf, 2, 3)));
The format attribute specifies that a function takes printf, scanf, strftime or strfmon style arguments which should be type-checked against a format string. In the example above, the format string is the second argument of the function foo and the arguments to check start with the third argument.