Pragma Directives

You typically use a #pragma directive to control the actions of the compiler in a particular portion of a program without affecting the program as a whole.

Put pragmas in your C++ source code where you want them to take effect. A pragma is in effect from the point where it is included to the end of the compilation unit or until another pragma changes its status.

A #pragma directive is an instruction to the compiler and is ignored during preprocessing.

Syntax:

#pragma pragma-string
pragma-string can be one of the following instructions to the compiler with any required parameters.

Pragma OPTIMIZE

Syntax:

#pragma OPTIMIZE ON 
#pragma OPTIMIZE OFF

Description:

Turns optimization on or off.

Use this pragma to turn off optimization in sections of a source program.

NOTE:

Example:

aCC +O2 prog.C

#pragma OPTIMIZE OFF
void A(){    // Turn off optimization
    ...      // for this function
}

#pragma OPTIMIZE ON
void B(){    // Restore optimization
    ...      // to level 2.
}


Pragma OPT_LEVEL

Syntax:

#pragma OPT_LEVEL 1
#pragma OPT_LEVEL 2
#pragma OPT_LEVEL 3
#pragma OPT_LEVEL 4

Description:

The OPT_LEVEL pragma sets the optimization level to 1, 2, 3, or 4.

NOTE:

Example:

aCC -O prog.C

#pragma OPT_LEVEL 1
void A(){      // Optimize this function at level 1.
   ...
}
#pragma OPT_LEVEL 2
void B(){      // Restore optimization to level 2.
   ...
}


Pragma HP_SHLIB_VERSION

Syntax:

#pragma HP_SHLIB_VERSION ["]date["]
The date argument is of the form month/year, optionally enclosed in quotes.

Description:

Creates different versions of a routine in a shared library.

HP_SHLIB_VERSION assigns a version number based on date to a module in a shared library. The version number applies to all global symbols defined in the module's source file.

This pragma should only be used if incompatible changes are made to a source file. If a version number pragma is not present in a source file, the version number of all symbols defined in the object module defaults to 1/90.

For More Information:


Pragma COPYRIGHT

Syntax:

#pragma COPYRIGHT "string"
string is the set of characters included in the copyright message in the object file.

Description:

Specifies a string to include in the copyright message and puts the copyright message into the object file.

If no date is specified (using pragma COPYRIGHT_DATE), the current year is used in the copyright message.

Examples:

Assuming the year is 1997, the directive

#pragma COPYRIGHT "Acme Software"

places the following string in the object code:

(C) Copyright Acme Software, 1997. All rights reserved.
No part of this program may be photocopied, reproduced, or
transmitted without prior written consent of Acme Software.

The following pragmas

#pragma COPYRIGHT_DATE "1990-1997"
#pragma COPYRIGHT "Brand X Software"

place the following string in the object code:

(C) Copyright Brand X Software, 1990-1997. All rights reserved.
No part of this program may be photocopied, reproduced, or
transmitted without prior written consent of Brand X Software.

NOTE: To see the COPYRIGHT string as well as any other strings in the object file, use the strings(1) command with the -a option for example:

strings -a ObjectFileName.o


Pragma COPYRIGHT_DATE

Syntax:

#pragma COPYRIGHT_DATE "string"
string is a date string used by the COPYRIGHT pragma.

Description:

Specifies a date string to be included in the copyright message.

Use the COPYRIGHT pragma to put the copyright message into the object file.

Example:

#pragma COPYRIGHT_DATE "1988-1992"
Places the string "1988-1992" in the copyright message.

NOTE: To see the COPYRIGHT_DATE string as well as any other strings in the object file, use the strings(1) command with the -a option for example:

strings -a ObjectFileName.o

Pragma LOCALITY

Syntax:

#pragma LOCALITY "string"
string specifies a name to be used for a code subspace.

Description:

Specifies a name to be associated with the code written to a relocatable object module.

All code following the LOCALITY pragma is associated with the name specified in string. Code that is not headed by a LOCALITY pragma is associated with the name $CODE$.

The smallest scope of a unique LOCALITY pragma is a function.

Example:

#pragma LOCALITY "MINE"
Builds the name $CODE$MINE$ and associates all code following this pragma with this name, unless another LOCALITY pragma is encountered.

Pragma VERSIONID

Syntax:

#pragma VERSIONID "string"
string is a string of characters that HP aC++ places in the object file.

Description:

Specifies a version string to be associated with a particular piece of code. The string is placed into the object file produced when the code is compiled.

Example:

#pragma VERSIONID "Software Product, Version 12345.A.01.05"

Places the characters Software Product, Version 12345.A.01.05 into the object file.

NOTE: To see the VERSIONID string as well as any other strings in the object file, use the strings(1) command with the -a option for example:

strings -a ObjectFileName.o