You can't do that, there's no support for a "foreach" type of iteration over the enumeration in C. Basically, enumerations are just aliased integers, with little extra support.
You need to use a mapping table, that allows you to map consecutive indices to values of the enumerated type:
static const myEnumType myEnumMap[] = { valueA, valueB, valueC, valueD, valueE};
then you can use a plain loop over that array:
for(size_t i = 0; i < sizeof myEnumMap / sizeof *myEnumMap; ++i)
{
const myEnumType ie = myEnumMap[i];
/* process ie */
}
Note that the type of myEnumMap
is the type of your enumeration, it's not a plain "array of integers".
This has the downside of requiring the enum to be enumerated twice (once in its own definition, then again in the myEnumMap
initializer). It's possible to work around that using macro trickery (such as X macros), but there's no real convenient/easy way to do it.