Specifying Priority Levels for Library Objects

The following section describes how to specify priority levels for objects, and how to set up a library containing files with objects at several priority levels. The examples are intended to show how you can specify priority levels for objects within a file and at the file level. You can also specify priority levels at the library level, as described in Constructing a Library. However, in most applications it is not necessary to specify more than one or two priority levels.

Specifying Priority Levels within a File
To specify the order of initialization of objects within a file, you use the #pragma priority(N) directive. You can use any number of directives within the file, but the priority numbers must be in increasing order. That is, you cannot specify an object with a smaller priority number after you have specified one with a larger priority number.

The following example shows how to specify the priority for several objects within a source file.

...
#pragma priority(5) //Following objects constructed with priority 5
...
static struct base A ;
class house B ;
...
#pragma priority(10) //Following objects constructed with priority 10
...
class barn C ;
...
#pragma priority(2) // Error - priority number must be larger
// than preceding number (10)
...
#pragma priority(20) //Following objects constructed with priority 20
...
class garage D ;
...

 

Specifying the Priority Level of a File
To specify the priority level of a file, you use the -qpriority=N compiler option, where N is the number you specify for the file's priority. Use this option if you want all the objects in the file to have the same priority level, and you do not want to write #pragma priority(N) directives in the file.

For example:

xlC farm.C -c -qpriority=20

produces an object file farm.o with a priority number of 20.

If there are no #pragma priority(N) directives within the file, all objects within the file have the priority specified with -qpriority=N.

If there are #pragma priority(N) directives within the file, all objects found within the file up to the first #pragma priority(N) directive are given the same priority number as specified for the file. The objects after a #pragma priority(N) directive are given that priority number of N until the next #pragma priority(N) directive is encountered.

Note: Within the file, the first #pragma priority(N) must have a higher priority number than the number used in the -qpriority=N option and subsequent #pragma priority(N) directives must have increasing numbers.


Overview of Shared Library Initialization
Example of Object Initialization in a Group of Files
Constructing a Library


priority Compiler Option