Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.1
Hello all,

I've an error 10.1 on the following C code:
#define MyConst 0x8A

My Code Review checker asks to add a U to the constant.

I'm quite surprised if it was a decimal value, I'll understand it but for an hexa, I don't really understand why ?

Another question is to know if a test set is present on the MISRA community to check the correct behaviour of the Code Review tool.

By advance thanks for your help.

Hello Philippe,

I think the reason why you are getting this error is that you are using this Macro with a unsigned variable in your file. So I will suggest that you also post the code where you are using this Macro for a better understanding.

It would be better to understand the behaviour.

Sorry for the delay of my answer.

See attached the code:
typedef unsigned char           FCMN_UINT8_T;


                        0x8E,  0xAD

Then, the table is composed of 2 bytes e.g. 0x8E and 0xAD. So as the value is expressed in hexadecimal. Why do we need to cast the 0x8E to (unsigned char).

Thanks for your help.
B/R Philippe
Hello all,

After a quick review, I though about that:
Do we need to specify if the 0x8E is either a unsigned value (142) or 0x8E (a negative value -114 as the Bit 7 is set to 1) ?

So, 0x8Eu to obviously type correctly the constant for unsigned value. Is it correct ?

Thanks by advance.
There will be a violation of rule 10.1 on the 0x8E and 0xAD because the type of the initialised object is "unsigned char".
In MISRA C:2012 this rule was relaxed so that assigning conversions (including initialisations) on signed literals to an unsigned type are permitted providing the value fits in the unsigned type.

In response to your other question. Example suites for both MISRA C:2004 and MISRA C:2012 can be found in the MISRA C resources section of this bulletin board at Board Index > Resources > MISRA C resources, which is accessible when logged in to the bulletin board.

Both example suites are also availble at
Posted by and on behalf of the MISRA C Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)