0

我在类似于以下的代码上运行 PC-Lint 8.00x:

typedef union
{
    struct
    {
        unsigned int blue  : 5;
        unsigned int green : 6;
        unsigned int red   : 5;
    };
    unsigned short color_value;
} Color_Type;

Color_Type my_color;
unsigned char blue;

blue = (unsigned char)my_color.blue;  /* Lint messages occur here */

PC-Lint 返回以下错误消息:

Error 40: Undeclared identifier 'blue'

Error 63: Expected an lvalue

代码按预期编译和运行。 我假设这是因为匿名结构,这个假设是否正确?如果是这样,我该如何在这种特殊情况下抑制这些消息? 我目前禁止在“options.lnt”文件中显示消息,因为我们的本地编码实践禁止将注释直接放在代码中以禁止 Lint 消息。

4

1 回答 1

1

当我发布这篇文章时,我回忆起曾几何时我设置了+fan标志,并认为应该涵盖这个案例。我决定再看一下 PC Lint 文档,并很快发现该标志只会抑制有关匿名工会的警告。

我还需要+fas在“options.lnt”文件中设置标志。

再次运行 PC Lint 后,我​​担心的所有警告都被抑制了。事实上,警告是由于匿名结构。

于 2013-11-25T18:41:55.183 回答