-qpriority (C++ only)

Category

Object code control

Pragma equivalent

#pragma options priority, #pragma priority

Purpose

Specifies the priority level for the initialization of static objects.

The C++ standard requires that all global objects within the same translation unit be constructed from top to bottom, but it does not impose an ordering for objects declared in different translation units. The -qpriority option and #pragma priority directive allow you to impose a construction order for all static objects declared within the same load module. Destructors for these objects are run in reverse order during termination.

Syntax

Read syntax diagramSkip visual syntax diagram
Option syntax

>>- -q--priority--=--number------------------------------------><

Read syntax diagramSkip visual syntax diagram
Pragma syntax

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

Defaults

The default priority level is 0.

Parameters

number
An integer literal in the range of -2 147 482 624 to 2147483647. A lower value indicates a higher priority; a higher value indicates a lower priority. Numbers from -214 783 648 to -214 782 623 are reserved for system use. If you do not specify a number, the compiler assumes 0.

Usage

More than one #pragma priority can be specified within a translation unit. The priority value specified in one pragma applies to the constructions of all global objects declared after this pragma and before the next one. However, in order to be consistent with the Standard, priority values specified within the same translation unit must be strictly increasing. Objects with the same priority value are constructed in declaration order.

The effect of a #pragma priority exists only within one load module. Therefore, #pragma priority cannot be used to control the construction order of objects in different load modules. Refer to Initializing static objects in libraries for further discussions on techniques used in handling static object initialization across modules.

Examples

To compile the file myprogram.C to produce an object file myprogram.o so that objects within that file have an initialization priority of 2 000, enter:
 xlc++ myprogram.C -c -qpriority=2000

Related information