简体   繁体   English

MISRA错误:字段类型应为int,unsigned int或signed int

[英]MISRA ERROR: field type should be int, unsigned int or signed int

I have used following code in my program and while running PC-Lint it throws following error: Multiple markers at this line - (lint:46) field type should be int, unsigned int or signed int [MISRA 2004 Rule 6.4, required] - (lint:960) Violates MISRA 2004 Required Rule 6.4, Bit field must be explicitly signed int or unsigned int 我在程序中使用了以下代码,并且在运行PC-Lint时会引发以下错误:此行上的多个标记-(lint:46)字段类型应为int,unsigned int或signed int [MISRA 2004 Rule 6.4,必填]- (lint:960)违反MISRA 2004要求的规则6.4,位字段必须显式标记为int或unsigned int

typedef struct{
  boolean ch8 :1;
  boolean Ch7 :1;
  boolean Ch6 :1;
  boolean Ch5 :1;
  boolean Ch4 :1;
  boolean Ch3 :1;
  boolean Ch2 :1;
  boolean Ch1 :1;
} Channel;

Can someone tell me how to fix this? 有人可以告诉我如何解决此问题吗?

You have to do it like this: 您必须这样做:

typedef struct{
  unsigned int ch8 :1;
  unsigned int Ch7 :1;
  unsigned int Ch6 :1;
  unsigned int Ch5 :1;
  unsigned int Ch4 :1;
  unsigned int Ch3 :1;
  unsigned int Ch2 :1;
  unsigned int Ch1 :1;
} Channel;

The only types a bitfield accepts, are integer types. 位域接受的唯一类型是整数类型。

MISRA-C:2004 is compatible with C:90 which does not have a boolean type. MISRA-C:2004与不具有boolean类型的C:90兼容。

To be perfectly compliant bit-fields have to be unsigned int or signed int 为了完全符合要求,位字段必须为unsigned intsigned int

Alternatively, you can document a Deviation (to Rule 1.1) to permit the use of the C99 boolean type - the rationale would be straightforward, as the corresponding MISRA C:2012 Rule (R 6.1) permits the use of boolean for bit fields. 或者,您可以记录偏差(规则1.1)以允许使用C99布尔类型-基本原理很简单,因为相应的MISRA C:2012规则(R 6.1)允许对位字段使用布尔值。

[Please note Profile disclaimer] [请注意个人资料免责声明]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM