本文介绍了我该如何为共进晚餐结构成员的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-林特定义如下:

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:

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

07-23 06:46
查看更多