Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

5.4.6 Example: Structs of Structs

Consider the following example source code.

struct bar;

struct foo {
        struct foo *ffp;
        struct bar *fbp;
} *fp;

struct bar {
        struct bar *bbp;
        long        b2;
} *bp;

The compiler’s assumptions based on various alias levels are the following:

  • If this example is compiled with the -xalias_level=weak option, only fp->ffp and bp->bbp can alias each other.

  • If this example is compiled with the -xalias_level=layout option, only fp->ffp and bp->bbp can alias each other.

  • If this example is compiled with the -xalias_level=strict option, no fields can alias because the two struct types are still different even after their tags are removed.

  • If this example is compiled with the -xalias_level=std option, no fields can alias because the two types and the tags are not the same.