我该如何为共进晚餐结构成员的C99风格的初始化preSS PC - 皮棉的错误? [英] How do I suppress PC-Lint errors for C99-style initialization of structure members?

查看:431
本文介绍了我该如何为共进晚餐结构成员的C99风格的初始化preSS PC - 皮棉的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的PC - 皮棉8.00x用下列选项:

+ V -wlib(1)+风扇+ FAS

我收到了一些错误消息从PC-林特当我运行类似于以下code:

 的typedef工会
{
    结构
    {
        unsigned int类型一:4;
        unsigned int类型A:4;
        unsigned int类型C:4;
        unsigned int类型D:4;
    }位;
    无符号短值;
} MY_VALUE;INT主要(无效)
{
    MY_VALUE测试[] =
    {
        {
            .bits.a = 2,
            .bits.b = 3,//错误133和10
            .bits.c = 2,
            .bits.d = 3,
        },
        {
            .bits.a = 1,
            .bits.b = 1,//误差133和10
            .bits.c = 1,
            .bits.d = 0,
        },
    };    / *做些有意义的事。 * /    返回0;
}

报告的错误是由PC-林特定义如下:


  

    

错误133:太多的初始化骨料'未知名


    
    

错误10:期待}


  

我试图寻找金培尔,也做了一些谷歌搜索,但我找不到任何有用的东西。按照预期,一切都正确初始化code函数。这里是我的问题。

1。请问结构成员的PC - 皮棉8.00x支持C99的风格初始化?

2。如果是这样,哪些选项/标志我必须为PC-林特全局设置为坐席preSS这些消息?

修改结果
我的问候已经更详细的回答问题2,我想全局燮preSS这些消息在问候我指定的初始值的使用如上图所示。我不能想喝preSS他们在全球范围适用于所有情况,因为这些错误可以在code检测真正的错误。


解决方案

据我所知,这语法:

  MY_VALUE测试[] =
{
    {
        .bits.a = 2,
        .bits.b = 3,
        .bits.c = 2,
        .bits.d = 3,
    },
    {
        .bits.a = 1,
        .bits.b = 1,
        .bits.c = 1,
        .bits.d = 0,
    },
};

在C99(和C11)有效。展望标准第6.7.8,事情$ P $在初始化pceding的 = 标志列表的,这是一个一个或多个标志的序列秒。 .bi​​ts.a 是在这方面有效。

显然,PC-林特不支持这种语法。 (您可能要通知维护人员,除非它在以后的版本已经支持)。

作为一种解决方法,如果你把它改成这样:

  MY_VALUE测试[] =
{
    {.bits =
        {
            .A = 2,
            .B = 3,
            .C = 2,
            .D = 3,
        },
    },
    {.bits =
        {
            .A = 1,
            .B = 1,
            .C = 1,
            .D = 0,
        },
    },
};

它仍然是有效的C(和可以清晰),并根据自己刚才在评论中写道,PC-lint接受它。

(如果你想更加明确的,你可以考虑加入 [0] = [1] = 代号。)

更新:报出新commment:


  

好的人金培尔软件已作出回应,指出这
  似乎是一个错误,并正在努力纠正。


I am using PC-Lint 8.00x with the following options:

+v -wlib(1) +fan +fas

I receive a number of error messages from PC-Lint when I run code similar to the following:

typedef union
{
    struct
    {
        unsigned int a : 4;
        unsigned int b : 4;
        unsigned int c : 4;
        unsigned int d : 4;
    } bits;
    unsigned short value;
} My_Value;

int main (void)
{
    My_Value test[] =
    {
        {
            .bits.a = 2,
            .bits.b = 3,    //Errors 133 and 10
            .bits.c = 2,
            .bits.d = 3,
        },
        {
            .bits.a = 1,
            .bits.b = 1,    //Errors 133 and 10
            .bits.c = 1,
            .bits.d = 0,
        },
    };

    /* Do something meaningful. */

    return 0;
}

The reported errors are defined by PC-Lint as follows:

Error 133: Too many initializers for aggregate 'unknown-name'

Error 10: Expecting '}'

I have tried searching Gimpel and have done some Google searches, but I cannot find anything useful. The code functions as intended and everything initializes properly. Here are my questions.

1. Does PC-Lint 8.00x support C99 style initialization of structure members?

2. If so, what options/flags do I have to set for PC-Lint to suppress these messages globally?

EDIT
I should have been more detailed in regards to question 2. I would like to globally suppress these messages in regards to my usage of designated initializers as shown above. I cannot suppress them globally for all situations as these errors can detect true errors in the code.

解决方案

As far as I can tell, this syntax:

My_Value test[] =
{
    {
        .bits.a = 2,
        .bits.b = 3,
        .bits.c = 2,
        .bits.d = 3,
    },
    {
        .bits.a = 1,
        .bits.b = 1,
        .bits.c = 1,
        .bits.d = 0,
    },
};

is valid in C99 (and C11). Looking in section 6.7.8 of the standard, the thing preceding the = in an initializer is a designator-list, which is a sequence of one or more designators. .bits.a is valid in that context.

Apparently PC-Lint doesn't support that syntax. (You might want to notify the maintainers, unless it's already supported in a later version.)

As a workaround, if you change it to this:

My_Value test[] =
{   
    { .bits =
        {   
            .a = 2,
            .b = 3,
            .c = 2,
            .d = 3,
        },
    },
    { .bits =
        {   
            .a = 1,
            .b = 1,
            .c = 1,
            .d = 0,
        },
    },
};

it's still valid C (and arguably clearer) and, based on what you just wrote in a comment, PC-Lint accepts it.

(If you want to be even more explicit, you might consider adding [0] = and [1] = designators.)

UPDATE : QUoting a new commment:

The good people at Gimpel software have responded stating that "this appears to be a bug" and are working to correct it.

这篇关于我该如何为共进晚餐结构成员的C99风格的初始化preSS PC - 皮棉的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆