Example of Object Initialization in a Group of Files

You can specify different priority numbers for objects within files, and the compiler will initialize them in the specified order. The following example describes describes the initialization order for objects in two files farm.C and zoo.C. Both files use #pragma priority(N) directives. Priority Levels for Objects in farm.C and zoo.C shows part of the files with #pragma priority(N) directives and hypothetical objects.

farm.C zoo.C
#pragma priority(20)
...                 
class dog A ;       
class dog B ;       
...                 
#pragma priority(100)        
...                  
class cat C ;        
class cow D ;        
...                  
#pragma priority(200)
class mouse E ;      
...                  
...               
class lion K ;      
#pragma priority(30)
class bear M ;      
...                 
#pragma priority(50)
...                 
class zebra N ;     
class snake S ;     
...                 
#pragma priority(250)
class frog F ;       
...               

Issuing the xlC command:

xlC farm.C zoo.C -c -qpriority=10

compiles farm.C and zoo.C to produce object files farm.o and zoo.o with an initialization priority number of 10.

These files are linked to form an executable file, animals:

xlC -oanimals farm.o zoo.o

The order in which initialization takes place is shown in the following table.

Object Priority Value Comment
"lion K" 10 Takes priority number of file "zoo.o" (10) (Initialized first)
"dog A" 20 Takes #PRAGMA PRIORITY(20) priority.
"dog B" 20 Follows "dog A"
"bear M" 30 Next priority number, specified by #PRAGMA PRIORITY(30)
"zebra N" 50 Next priority number from #PRAGMA PRIORITY(50)
"snake S" 50 Follows with same priority
"cat C" 100 Next priority number
"cow D" 100 Follows with same priority
"mouse E" 200 Next priority number
"frog F" 250 Next priority number (Initialized last).


Overview of Shared Library Initialization
Specifying Priority Levels for Library Objects
Constructing a Library


priority Compiler Option