Nullstone Logo

COMPANY
Home
Contacts
Customers
Testimonials

PRODUCTS
Overview
NULLSTONE for C
NULLSTONE for Java
Technical Overview

SUPPORT
Release Notes
Download
PGP Information
Service Report
Write Us

INFORMATION
Performance Results
Glossary of Terms

RELATED LINKS
Compiler Connection
Compiler Jobs

Previous Up Next
Alias Optimization (by type)

The ANSI C standard specifies the following regarding the circumstances in which an object may or may not be aliased.

An object shall have its stored value accessed only by an lvalue that has one of the following types:

  • the declared type of the object,
  • a qualified version of the declared type of the object,
  • a type that is the signed or unsigned type corresponding to the declared type of the object,
  • a type that is the signed or unsigned type corresponding to a qualified version of the declared type of the object,
  • an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a sub-aggregate or contained union), or
  • a character type.
This means, for example, that a compiler can assume that a pointer to an object of type short is not an alias for a pointer to an object of type int, and perform optimizations based on this assumption.

Example:

In the code fragment below, the lvalues ps and pi have different types, and the compiler can assume they are not aliased.

    void f (short *ps, int *pi)
    {
      int i, j;
      i = *pi;
      *ps = 3;
      j = *pi;
      g (i, j);
    }
    

Since ps and pi can not be aliased, the store through ps can not change the object pointed to by pi, and the second reference to the object pointed to by pi can be eliminated, as shown below.

    void f (short *ps, int *pi)
    {
      int i, j;
      i = *pi;
      *ps = 3;
      g (i, i);
    }
    

Notes:

Although specified in the ANSI C standard as undefined behavior, some programs use aliasing. To support these programs, some compilers avoid alias optimization by type, or provide user-selectable options to inhibit this optimization.

© 1990-2012 Nullstone Corporation. All Rights Reserved.