【问题标题】:How do I suppress Lint messages in regards to anonymous structs?如何抑制与匿名结构有关的 Lint 消息?
【发布时间】:2013-11-25 18:41:55
【问题描述】:

我在类似于以下的代码上运行 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”文件中的消息,因为我们的本地编码实践禁止将 cmets 直接放在代码中以抑制 Lint 消息。

【问题讨论】:

    标签: c lint pc-lint


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 2023-03-13
      • 2018-07-09
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多