Rule 10.3 - Bitfield narrower essential type

Moderators: misra-c, david ward

Post Reply
apereira
Posts: 4
Joined: Fri Feb 08, 2019 12:57 pm
Company: Infineon Technologies

Rule 10.3 - Bitfield narrower essential type

Post by apereira » Thu Oct 24, 2019 7:01 am

Hello,

Assuming that I have the following structure and enum:

Code: Select all

  typedef struct s{
  unsigned int a:5;
  unsigned int b:1;
  unsigned int c:1;
} s;

typedef enum e{
  ZERO = 0,
  ONE = 1,
  TWO = 2,
  THREE = 3
} e;
Why does the following code trigger rule 10.3?

Code: Select all

s fcn(void)
{
  s test;

  test.a = (unsigned int) THREE;

  return test;
}

Post Reply

Return to “8.10 The essential type model”