HP aC++/HP C A.06.25 Programmer's Guide
3 Pragma Directives and Attributes
A pragma directive is an instruction to the compiler. You use a #pragma directive to
control the actions of the compiler in a particular portion of a translation unit without
affecting the translation unit as a whole.
Put pragmas in your C++ source code where you want them to take effect. Unless
otherwise specified, a pragma is in effect from the point where it is included until the
end of the translation unit or until another pragma changes its status.
This chapter discusses the following pragma directives:
• “Initialization and Termination Pragmas” (page 127)
• “Copyright Notice and Identification Pragmas” (page 128)
• “Data Alignment Pragmas” (page 129)
• “Optimization Pragmas” (page 135)
• “Diagnostic Pragmas” (page 139)
• “Other Pragmas” (page 139)
• “OpenMP Clauses” (page 150)
• “Attributes” (page 153)
Initialization and Termination Pragmas
This section describes the INIT and FINI pragmas. These pragmas 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, its initializers and terminators are also executed at the
appropriate time.
INIT
#pragma INIT “string”
Use #pragma INIT to specify an initialization function. The function takes no
arguments and returns 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 ... }
FINI
#pragma FINI “string”
Initialization and Termination Pragmas 127