04-10-2018, 10:30 AM
Francois Wrote:HiCheck the table in MISRA C 2012 Appendix D.1: both operands are essentially unsigned.
Isn't there a rule to ensure that comparison is perform on same object type?
The table in rule 10.1 poses no restrictions on operator < for essentially unsigned operands.
If both operands are supposed to be of the same essential type (not just the same essential type category): that is not clearly stated IMHO.
IMHO, currently the bug would be catched only if there is a narrowing assignment which is prohibited by rule 10.3 (see below).
Anyhow, an official clarification would be nice.
Code:
#include
int main(void)
{
unsigned char var1 = 0;
unsigned short var2 = 300;
const unsigned char cmp = var2;/*Expression assigned to a narrower or different essential type [MISRA 2012 Rule 10.3, required]*/
while (var1 < cmp)
{
var1++;
}
(void)printf("program completed \n ");
return 0;
}
<t></t>