Sun Studio 12:C 用户指南

5.3.1 标量指针向结构指针的强制类型转换

在以下示例中,整型指针 p 强制转换为 struct foo 类型的指针。如果 lint -Xalias_level=weak(或更高),这将生成错误。


struct foo {
    int a;
    int b;
  };

struct foo *f;
int *p;

void main()
{
    f = (struct foo *)p; /* struct pointer cast of scalar pointer error */
}