Oracle® Solaris Studio 12.4:C 用户指南

退出打印视图

更新时间: 2014 年 12 月
 
 

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

在下面的示例中,结构成员 foo.b 的地址被强制转换为结构指针,然后指定给 f2。如果 lint -Xalias_level=weak(或更高),此示例将生成错误。

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