Rule 10.1

6.10 Arithmetic Type Conversions

Moderators: misra-c, david ward

Posts: 5
Joined: Sun Jun 24, 2018 11:34 pm
Company: Capgemini

Rule 10.1

Postby phdenis » Wed Jul 18, 2018 10:30 am

Hello all,

I've an error 10.1 on the following C code:

Code: Select all

#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.


Posts: 14
Joined: Wed Feb 14, 2018 10:02 am
Company: Inform GmbH

Re: Rule 10.1

Postby ankitshah413 » Thu Jul 19, 2018 8:05 am

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.


Posts: 5
Joined: Sun Jun 24, 2018 11:34 pm
Company: Capgemini

Re: Rule 10.1

Postby phdenis » Tue Jul 31, 2018 9:53 pm

Sorry for the delay of my answer.

See attached the code:

Code: Select all

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

Posts: 5
Joined: Sun Jun 24, 2018 11:34 pm
Company: Capgemini

Re: Rule 10.1

Postby phdenis » Wed Aug 29, 2018 9:48 am

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.

Posts: 547
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 10.1

Postby misra-c » Thu Oct 04, 2018 11:04 am

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

Return to “6.10 Arithmetic Type Conversions”

Who is online

Users browsing this forum: No registered users and 1 guest