Sun Studio 12 Update 1: C User's Guide

5.3.3 Cast of Struct Field to Structure Pointer

In the following example, the address of structure member foo.b is being cast as a struct pointer and then assigned to f2. With lint -Xalias_level=weak (or higher), this generates an error.


struct foo{
    int a;
    int b;
  };

struct foo *f1;
struct foo *f2;

void main()
{
    f2 = (struct foo *)&f1->b; /* cast of a scalar pointer to struct pointer error*/
}