MISRA C:2012 Rule 8.12
Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
Description
Rule Definition
Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique1 .
Rationale
An implicitly specified enumeration constant has a value one greater than its predecessor. If the first enumeration constant is implicitly specified, then its value is 0. An explicitly specified enumeration constant has the specified value.
If implicitly and explicitly specified constants are mixed within an enumeration list, it is possible for your program to replicate values. Such replications can be unintentional and can cause unexpected behavior.
Polyspace Implementation
The rule checker flags an enumeration if it has an implicitly specified enumeration constant with the same value as another enumeration constant.
Additional Message in Report
The constant constant1
has same value
as the constant constant2
.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declarations and Definitions |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2014b
See Also
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.