Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

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 example 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*/
}