HP C Programmer's Guide (92434-90009)

100 Chapter4
Optimizing HP C Programs
Optimizer Pragmas
Optimizer Pragmas
Pragmas give you the ability to:
Control compilation in finer detail than what is allowed by command line options.
Give information about the program to the compiler.
Pragmas cannot cross line boundaries and the word pragma must be in lowercase letters.
Optimizer pragmas may not appear inside a function.
Optimizer Control Pragmas
The OPTIMIZE and OPT_LEVEL pragmas control which functions are optimized, and which
set of optimizations are performed. These pragmas can be placed before any function
definitions and override any previous pragma. These pragmas cannot raise the
optimization level above the level specified in the command line.
OPT_LEVEL 0, 1, and 2 provide more control over optimization than the +O1 and +O2
compiler options because these pragmas can be used to raise or lower optimization at a
function by function level inside the source file using different levels for different
functions. Whereas, the compiler options can only be used for an entire source file.
(OPT_LEVEL 3 and 4 can only be used at the beginning of the source file.)
<Undefined Cross-Reference> shows the possible combinations of options and pragmas
and the resulting optimization levels. The level at which a function will be optimized is the
lower of the two values specified by the command line optimization level and the
optimization pragma in force.
Table 4-6. Optimization Level Precedence
Command-line
Optimization
Level
#Pragma
OPT_LEVEL
Resulting
OPT_LEVEL
none OFF 0
none 1 0
none 2 0
+O1 OFF 0
+O1 11
+O1 21
+O1 31
+O1 41
+O2 OFF 0
+O2 11
+O2 22