#pragma disjoint

Category

Optimization and tuning

Purpose

Lists identifiers that are not aliased to each other within the scope of their use.

By informing the compiler that none of the identifiers listed in the pragma shares the same physical storage, the pragma provides more opportunity for optimizations.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-#pragma disjoint--------------------------------------------->

                                 .------------------------------.      
                                 V                              |      
>--(--+--------+--variable_name----,--+--------+--variable_name-+--)-><
      | .----. |                      | .----. |                       
      | V    | |                      | V    | |                       
      '--- *-+-'                      '--- *-+-'                       

Parameters

variable_name
The name of a variable. It must not refer to any of the following:
  • A member of a structure or union
  • A structure, union, or enumeration tag
  • An enumeration constant
  • A typedef name
  • A label

Usage

The #pragma disjoint directive asserts that none of the identifiers listed in the pragma share physical storage; if any the identifiers do actually share physical storage, the pragma may give incorrect results.

The pragma can appear anywhere in the source program that a declaration is allowed. An identifier in the directive must be visible at the point in the program where the pragma appears.

You must declare the identifiers before using them in the pragma. Your program must not dereference a pointer in the identifier list nor use it as a function argument before it appears in the directive.

This pragma can be disabled with the -qignprag compiler option.

Examples

The following example shows the use of #pragma disjoint.
int a, b, *ptr_a, *ptr_b;

#pragma disjoint(*ptr_a, b)   /* *ptr_a never points to b */
#pragma disjoint(*ptr_b, a)   /* *ptr_b never points to a */
one_function()
{
     b = 6;
     *ptr_a = 7;   /* Assignment will not change the value of b  */

   another_function(b);    /* Argument "b" has the value 6  */
}
External pointer ptr_a does not share storage with and never points to the external variable b. Consequently, assigning 7 to the object to which ptr_a points will not change the value of b. Likewise, external pointer ptr_b does not share storage with and never points to the external variable a. The compiler can assume that the argument to another_function has the value 6 and will not reload the variable from memory.