HP C A.06.05 Reference Manual

Compiling and Running HP C Programs
Pragmas
Chapter 9226
Pragmas
A #pragma directive is an instruction to the compiler. Put pragmas in your C source code
where you want them to take effect, but do not use them within a function. A pragma has
effect from the point at which it is included to the end of the translation unit (or until another
pragma changes its status).
This section introduces the following groups of HP C compiler directives:
Initialization and Termination Pragmas
Copyright Notice and Identification Pragmas
Data Alignment Pragmas
Optimization Pragmas
FastCall Pragmas
Gather/Scatter Prefetch Pragma
Initialization and Termination Pragmas
This section describes the INIT and FINI pragmas. These allow the user to set up functions
which are called when a load module (a shared library or executable) is loaded (initializer) or
unloaded (terminator). For example, when a program begins execution, its initializers get
called before any other user code gets called. This allows some set up work to take place. In
addition, when the user’s program ends, the terminators can do some clean up. When a shared
library is loaded or unloaded with the shl_load or dlopen API, its initializers and
terminators are also executed at the appropriate time.
INIT Pragma
#pragma INIT “
string
Use the compiler pragma INIT to specify an initialization function. The functions take no
arguments and return nothing. The function specified by the INIT pragma is called before the
program starts or when a shared library is loaded.
For example:
#pragma INIT “my_init”
void my_init() {
...do some initializations ...
}