26-03-2020, 10:53 AM
Hello everyone,
I have 2 functions below, the top one, I get a MISRAC2012-Rule-16.1 warning, the second one I do not get the warning, the only difference between them is where 'i' is declared.
Is the warning I am seeing correct? If it is why is it not allowed?
I have looked through the 16.x rules and I could not see anything that suggested I could it was banned.
I am using IAR C-STAT to do the analysis.
Thanks,
James
I have 2 functions below, the top one, I get a MISRAC2012-Rule-16.1 warning, the second one I do not get the warning, the only difference between them is where 'i' is declared.
Is the warning I am seeing correct? If it is why is it not allowed?
I have looked through the 16.x rules and I could not see anything that suggested I could it was banned.
I am using IAR C-STAT to do the analysis.
Code:
/***************
* I get the following warning on this switch statement: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed.
***************/
uint32_t func(uint32_t num)
{
uint32_t result;
switch(num)
{
case 0:
{
result = 123U;
break;
}
case 1:
{
result = 567U;
for (uint32_t i = 0U; i < 10U; i++)
{
result = i + result;
}
break;
}
default:
{
result = 0;
break;
}
}
return result;
}
uint32_t func_b(uint32_t num)
{
uint32_t result;
switch(num)
{
case 0:
{
result = 123U;
break;
}
case 1:
{
uint32_t i;
result = 567U;
/***************
* If I declare 'i' outside of the loop this warning goes away: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed.
***************/
for (i = 0U; i < 10U; i++)
{
result = i + result;
}
break;
}
default:
{
result = 0;
break;
}
}
return result;
}
Thanks,
James
<t></t>