PC-lint编译问题

2020-02-08 12:22发布

各位,我声明了一个这样的变量:
union
{
    struct
    {
        unsigned cell_cap:3;
        unsigned outpow:1;
        unsigned charging:1;
        unsigned :2;
    }
    unsigned char Byte;
}Power_Info
我做一个判断语句,只能写成这个样子:
if(((Power_Info.Byte & 0x07) == 0x00) && ((Power_Info.Byte & 0x8) == 0x00))
才能用PC-lint编译通过,但这样的话我的变量就直接声明成一个普通的unsigned char就得了,里面的位再细分也白分了。
如果写成这样:
if((Power_Info.cell_cap == 0x00) && (Power_Info.OutPow == 0x00))
就会报错:
Implicit binary conbersion from int to unsigned int
如果写成这样:
if((Power_Info.cell_cap == 0b000) && (Power_Info.OutPow == 0b0))
就会报错:
Assuming a binary constant

高人请指教啊!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
11条回答
theophilus
1楼-- · 2020-02-08 16:24
Assuming a binary constant  -- A constant of the form
      0b... was encountered.  This was taken to be a binary
      constant.  For example, 0b100 represents the value 4.  If
      your compiler supports binary constants you may suppress
      this message.

主要是因为0b不是标准C的内容
huanghaiming
2楼-- · 2020-02-08 19:30
蛋疼啊,是不是意味着没办法单独使用变量的位啦?
theophilus
3楼-- · 2020-02-08 23:53
是可以用的,但与pc-lint的选项有关。
但是推荐字面量制定类型比如0x00U
huanghaiming
4楼-- · 2020-02-09 00:41
楼上的,能不能具体说说,怎么实现?0x00U是什么?网上很少相关资料啊。
huanghaiming
5楼-- · 2020-02-09 06:04
 精彩回答 2  元偷偷看……
theophilus
6楼-- · 2020-02-09 07:49
lint是一个可配置的契约,不知道相应契约规范的话,我不知道你用lint干啥。

一周热门 更多>