Enumeration specifiers - 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: Enumeration specifiers (/showthread.php?tid=275) |
Enumeration specifiers - fwamolina - 20-06-2006 My question is if the code bellow is not compliance with misrac-2004 uint16_t GetSpeed (void); void IncreaseSpeed (void); void DecreaseSpeed (void); void GoodSpeed (void); enum tagSPEED { Low, Medium, High }; void main (void) { uint16_t uSpeed; uSpeed = GetSpeed(); switch (uSpeed) { case Low: IncreaseSpeed(); break; case Medium: GoodSpeed (void); break; case High: DecreaseSpeed (void); break; default: break; } } Is there any solution for this case? Normative reference: Ansi-Iso-9899-1990 (6.5.2.2) Misra-c2004 (6.10.3) - misra-c - 22-08-2006 MISRA-C meeting 22-8-2006 The type of the enumeration constant is defined by ISO to be signed int. In your example, the switch selector has type unsigned int, and the case constants have type signed int. This is a violation of rule 10.1. |