Sun Studio 12:C 用户指南

5.3.3 结构字段向结构指针的强制类型转换

在以下示例中,结构成员 foo.b 的地址被强制转换为结构指针,然后分配给 p。如果 lint -Xalias_level=weak(或更高),这将生成警告。


struct foo p{
    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*/
}