Oracle® Solaris Studio 12.4:C 用户指南

退出打印视图

更新时间: 2014 年 12 月
 
 

5.3.4 需要显式别名

在以下示例中,struct fooa 类型的指针 f1 正在被强制转换为 struct foob。使用 lint -Xalias_level=strict 或更高级别时,这种强制转换需要显式别名,除非 struct 类型是相同的(相同类型的相同数目的字段)。此外,在别名级别 standardstrong 上,假定标记必须匹配才能出现别名。在给 f1 赋值前使用 #pragma aliasstruct fooastruct foob),lint 将停止生成警告。

struct fooa {
    int a;
};

struct foob {
    int b;
};

struct fooa *f1;
struct foob *f2;

void main()
{
    f1 = (struct fooa *)f2; /* explicit aliasing required warning */
}