Rule 10.1 - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.10 Arithmetic Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=37) +---- Thread: Rule 10.1 (/showthread.php?tid=1440) |
Rule 10.1 - phdenis - 18-07-2018 Hello all, I've an error 10.1 on the following C code: 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. B/R Philippe Re: Rule 10.1 - ankitshah413 - 19-07-2018 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. Regards, Ankit Re: Rule 10.1 - phdenis - 31-07-2018 Hello, Sorry for the delay of my answer. See attached the code: Code: typedef unsigned char FCMN_UINT8_T; 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 Re: Rule 10.1 - phdenis - 29-08-2018 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. Re: Rule 10.1 - misra-c - 04-10-2018 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 https://gitlab.com/MISRA/MISRA-C/ |