#pragma priority (C++)

Description

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

Syntax

Where n is an integer literal in the range of INT_MIN to INT_MAX. The default value is 0. A negative value indicates a higher priority; a positive value indicates a lower priority. The first 1024 priorities (INT_MIN to INT_MIN + 1023) are reserved for use by the compiler and its libraries. The priority value specified applies to all runtime static initialization in the current compilation unit.

Any global object declared before another object in a file is constructed first. Use #pragma priority to specify the construction order of objects across files. However, if the user is creating an executable or shared library target from source files, VisualAge C++ will check dependency ordering, which may override #pragma priority.

For example, if the constructor to object B is passed object A as a parameter, then VisualAge C++ 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 VisualAge C++ permits. If the target is an .obj/.lib, this processing is not done, because there may not be enough information to detect the dependencies.

To ensure that the objects are always constructed from top to bottom in a file, the compiler enforces the restriction that the priority specifies all objects before and all objects after it until the next #pragma (is encountered) is at that priority.

For example,

#pragma priority(1)


Preprocessor Directives - An Overview
Preprocessor Directive - #pragma