04-09-2025, 11:06 AM
Can we have a new rule that says
Surely we would want to know/acknowledge that enum has a gap if we plan to iterate over it.
(regardless where the 'for' loop starts/end)
It would make a good higher level/abstraction rule.
Or at least make it advisory.
Quote: if enum is used as an iterator type then there shall not be gaps in enum values.
Code:
typedef enum
{
PIN_A = 1,
//missing 2
PIN_B = 3,
PIN_C = 4,
PIN_MAX,
} tPin;
for(tPin i = PIN_A ; i < PIN_MAX; i++)
{
// i reaching 2 is unintended/refactoring/human error
}
Surely we would want to know/acknowledge that enum has a gap if we plan to iterate over it.
(regardless where the 'for' loop starts/end)
It would make a good higher level/abstraction rule.
Or at least make it advisory.