#pragma priority

C++ only


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


Read syntax diagramSkip visual syntax diagram>>-#--pragma--priority--(--n--)--------------------------------><


The value of n must be an integer literal in the range of INT_MIN to INT_MAX-2147483643 to 2147483647. 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 applies to all global and static objects following the #pragma priority directive, unless 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.


#pragma priority(1001)

Related information