26-11-2015, 10:21 AM
Iterating over an enumeration is non-compliant with MISRA C:2012, because in general it is not known that all values in the iteration loop exist as enumeration values. For example An alternative way of writing the loop would be but this does violate rule 10.1 as ++ is not allowed on objects with an enumeration type.
Both the original and the alternative way of writing the loop would require a deviation. The deviation would need to include the information that
Code:
typedef enum { EA =1, EB = 3, ELAST = 5 } en1;
Code:
for ( adc_t en = ADC_VBAT; en < ADC_NUM_SIGNALS; en++ )
{
AdcClearAverage( en ) ;
}
Both the original and the alternative way of writing the loop would require a deviation. The deviation would need to include the information that
- 1. The enumeration type contained no gaps in the numbering sequence
2. The start and end points of the loop were members of the enumeration type
Posted by and on behalf of the MISRA C Working Group