HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)
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 116)
• “Copyright Notice and Identification Pragmas” (page 117)
• “Data Alignment Pragmas” (page 118)
• “Optimization Pragmas” (page 124)
• “Diagnostic Pragmas” (page 127)
• “Other Pragmas” (page 128)
• “OpenMP Clauses” (page 139)
• “Attributes” (page 142)
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 ... }
116 Pragma Directives and Attributes