Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

5.3.4 Explicit Aliasing Required

In the following example, the pointer f1 of type struct fooa is being cast as a pointer of type struct foob. With lint -Xalias_level=strict (or higher) such a cast requires explicit aliasing, unless the struct types are identical (the same number of fields of the same type). In addition, at alias levels standard and strong, the assumptions is that the tags must match for aliasing to occur. Use #pragma alias (struct fooa, struct foob) before the assignment to f1 and lint stops generating the warning.

struct fooa {
    int a;
};

struct foob {
    int b;
};

struct fooa *f1;
struct foob *f2;

void main()
{
    f1 = (struct fooa *)f2; /* explicit aliasing required warning */
}