Rule 10.6: \"u\" Suffix to all unsigned constants - 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.6: \"u\" Suffix to all unsigned constants (/showthread.php?tid=280) |
Rule 10.6: \"u\" Suffix to all unsigned constants - Manni - 26-06-2006 Hello I have a disagreement with a supporter of a bigger MISRA-C:2004 rule checking tool. He means, that the following is MISRA-C:2004 compliant : Code: void foo(UINT b) I mean, it is not compliant . There must be \"u\"-Suffix: Code: void foo(UINT b) 1. reason: \"Rule 10.6 (required): A \"U\" suffix shall be applied to all constants of unsigned type.\" I think, it is a clear case, when I read this rule. There is spoken from \"all\" constants of unsigned Type. So why there should be no \"u\" Suffix? 2. reason: In \"Rule 10.1 (required):\" in MISRA-C:2004, are examples for this: MISRA-C:2004 in Rule 10.1/10.2 Code: ... u8a + 5 /* not compliant */ For me it is really a clear case, there must be a \"u\" suffix at the constant. But we need to clarify it, with an official answer for this tiny problem. Thanks - Hammer - 27-06-2006 I am also interested in this rule. Code: #define BIT0 0x0001 I take from the wording of the rule that a 'U' suffix needs to be applied in this case. Also Code: uint32_t x=1U; Is this compliant. The U suffix has not been used but isnt this the same? - Manni - 28-06-2006 I think using a typcast (uint32_t) instead of a \"u\" suffix at a constant, is MISRA compliant. But it's only my opinion. Let us wait, for official answers. - misra-c - 23-08-2006 MISRA-C meeting 23-8-2006 From page 43 Code: ... u8a + 5 /* not compliant */ Either casting or use of U is acceptable. Does example for Rule 17.4 violate Rule 10.1? - mhabermann - 20-10-2006 Rule 17.4 has the example: uint8_t index = 0; ... index = index + 5; How does this go along with: u8a + 5; /* not compliant */ - misra-c - 21-11-2006 MISRA-C Steering Meeting 7th November 2006 You are correct, this is an error. The line should have read Code: index = index + 5U; See highlighted corrections to the example 17.4. Changes denoted by /*#*/ Code: void my_fn(uint8_t * p1, uint8_t p2[]) |