Go to main content
Oracle® Developer Studio 12.6: C++ User's Guide

Exit Print View

Updated: July 2017
 
 

Pragmas

This appendix describes the C++ compiler pragmas. A pragma is a compiler directive that enables the programmer to provide additional information to the compiler. This information can change compilation details that are not otherwise under your control. For example, the pack pragma affects the layout of data within a structure. Compiler pragmas are also called directives.

The preprocessor keyword pragma is part of the C++ standard, but the form, content, and meaning of pragmas is different for every compiler. No pragmas are defined by the C++ standard.


Note - Code that depends on pragmas is not portable.

B.1 Pragma Forms

The various forms of a C++ compiler pragma are:

#pragma keyword
#pragma keyword ( a [ , a ] ...) [ , keyword ( a [ , a ] ...) ] ,...
#pragma sun keyword

The variable keyword identifies the specific directive; a indicates an argument.

B.1.1 Overloaded Functions as Pragma Arguments

Several pragmas listed in this appendix take function names as arguments. In the event that the function is overloaded, the pragma uses the function declaration immediately preceding the pragma as its argument. Consider the following example:

int bar(int);
int foo(int);
int foo(double);
#pragma does_not_read_global_data(foo, bar)

In this example, foo means foo(double), the declaration of foo immediately preceding the pragma, and bar means bar(int), the only declared bar. Now, consider this following example in which foo is again overloaded:

int foo(int);
int foo(double);
int bar(int);
#pragma does_not_read_global_data(foo, bar)

In this example, bar means bar(int), the only declared bar.However, the pragma will not know which version of foo to use. To correct this problem, you must place the pragma immediately following the definition of foo that you want the pragma to use.

The following pragmas use the selection method described in this section:

  • does_not_read_global_data

  • does_not_return

  • does_not_write_global_data

  • no_side_effect

  • opt

  • rarely_called

  • returns_new_memory