MISRA C:2023 Rule 8.12
Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
Since R2024a
Description
Rule Definition
Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique.
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.
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 R2024a