Sun Studio 12:C 用户指南

5.3.2 空指针向结构指针的强制类型转换

在以下示例中,空指针 vp 强制转换为结构指针。如果 lint -Xalias_level=weak(或更高),这将生成警告。


struct foo {
    int a;
    int b;
  };

struct foo *f;
void *vp;

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