#pragma priority

Applies to C++

Description

The #pragma priority directive specifies the order in which static objects are to be initialized.

Syntax

>>-#--pragma--priority--(--n--)--------------------------------><
 
 

Notes

The value of n must be an integer literal in the range of 101 to 65535. The default value is 65535. A lower value indicates a higher priority; a higher value indicates a lower priority.

The priority value applies to all global and static objects following the #pragma priority directive, unless an explicit value is given by the variable attribute init_priority or another #pragma priority directive is encountered.

Objects with the same priority value are constructed in declaration order. Use #pragma priority to specify the construction order of objects across files. However, if you are creating an executable or shared library target from source files, the compiler will check dependency ordering, which may override #pragma priority.

For example, if a copy of object A is passed as a parameter to the object B constructor, then the compiler will arrange for A to be constructed first, even if this violates the top-to-bottom or #pragma priority ordering. This is essential for orderless programming, which the compiler permits. If the target is an .obj/.lib, this processing is not done, because there may not be enough information to detect the dependencies.

Variable attribute init_priority

The C++ variable attribute init_priority can also be used to assign a priority level to a shared variables of class type. See XL C/C++ Language Reference for more information.

Example

#pragma priority(1001)

Related references

IBM Copyright 2003