abhay agrawal
abhay agrawal

Reputation: 35

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

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?

Upvotes: 0

Views: 3175

Answers (2)

Andrew
Andrew

Reputation: 2322

MISRA-C:2004 is compatible with C:90 which does not have a boolean type.

To be perfectly compliant bit-fields have to be unsigned int or signed 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.

[Please note Profile disclaimer]

Upvotes: 0

Vincent
Vincent

Reputation: 646

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.

Upvotes: 2

Related Questions