Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ User's Guide - the "initialize" pragma sets the priority for initialization of static data http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
The "initialize" pragma sets the priority for initialization of static data
in the file.  This priority only applies to initialization of static data
that requires the execution of code.  For example, the initialization of a
class that contains a constructor requires the execution of the constructor.
 Note that if the sequence in which initialization of static data in your
program takes place has no dependencies, the "initialize" pragma need not be
used.

The general form of the "initialize" pragma is as follows.

+--------------------------------------------------------------------------+
|      #pragma initialize [before | after] priority [;]                    |
|                                                                          |
|      priority ::= n | library | program                                  |
|                                                                          |
+--------------------------------------------------------------------------+

where
    description

n
    is a number representing the priority and must be in the range 0-255.
     The larger the priority, the later the point at which initialization
    will occur.

Priorities in the range 0-20 are reserved for the C++ compiler.  This is to
ensure that proper initialization of the C++ run-time system takes place
before the execution of your program.  The "library" keyword represents a
priority of 32 and can be used for class libraries that require
initialization before the program is initialized.  The "program" keyword
represents a priority of 64 and is the default priority for any compiled
code.  Specifying "before" adjusts the priority by subtracting one.
 Specifying "after" adjusts the priority by adding one.

A source file containing the following "initialize" pragma specifies that
the initialization of static data in the file will take place before
initialization of all other static data in the program since a priority of
63 will be assigned.

Example:

     #pragma initialize before program

If we specify "after" instead of "before", the initialization of the static
data in the file will occur after initialization of all other static data in
the program since a priority of 65 will be assigned.

Note that the following is equivalent to the "before" example

Example:

     #pragma initialize 63

and the following is equivalent to the "after" example.

Example:

     #pragma initialize 65

The use of the "before", "after", and "program" keywords are more
descriptive in the intent of the pragmas.

It is recommended that a priority of 32 (the priority used when the
"library" keyword is specified) be used when developing class libraries.
 This will ensure that initialization of static data defined by the class
library will take place before initialization of static data defined by the
program.  The following "initialize" pragma can be used to achieve this.

Example:

     #pragma initialize library

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson