Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.6: \"u\" Suffix to all unsigned constants
#1
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)
{
UINT a;

a = b + 30;
}

I mean, it is not compliant . There must be \"u\"-Suffix:
Code:
void foo(UINT b)
{
UINT a;

a = b + 30[b]u[/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 */

... u8a + 5U /* 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
<t>best regards,<br/>
Manni</t>
#2
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;
uint32_t y;

y=x+(uint32_t)1; /*Cast instead of 'U' */

Is this compliant. The U suffix has not been used but isnt this the same?
#3
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.
<t>best regards,<br/>
Manni</t>
#4
MISRA-C meeting 23-8-2006

From page 43

Code:
... u8a + 5                           /* not compliant */
    ... u8a + 5U                         /* compliant     */
    ... u8a + (uint8_t)5               /* compliant     */

Either casting or use of U is acceptable.
Posted by and on behalf of the MISRA C Working Group
#5
Rule 17.4 has the example:

uint8_t index = 0;
...
index = index + 5;

How does this go along with:
u8a + 5; /* not compliant */
#6
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[])
{
   uint8_t index = 0U; /*#*/
   uint8_t * p3;
   uint8_t * p4;

   *p1 = 0U; /*#*/
   p1 ++;       /* not compliant – pointer increment               */
   p1 = p1 + 5; /* not compliant – pointer increment               */
   p1[5] = 0U; /*#*/  /* not compliant – p1 was not declared as an array */
   p3 = &p1[5]; /* not compliant – p1 was not declared as an array */
   p2[0] = 0U; /*#*/
   index ++;
   index = index + 5U; /*#*/
   p2[index] = 0U; /*#*//* compliant     */
   p4 = &p2[5];   /* compliant     */
}
uint8_t a1[16];
uint8_t a2[16];

my_fn(a1, a2);

my_fn(&a1[4], &a2[4]);

uint8_t a[10];
uint8_t * p;
p = a;
*(p+5) = 0U; /*#*//* not compliant */
p[5] = 0U;   /*#*//* compliant     */
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 1 Guest(s)