What are the common misuses of “enum” in C

cenum

I have seen C code where people used enum heavily. But all it does is confuse others. In many places plain integers can do the same thing with less ambiguity. What are the common misuses of enum?

Best Answer

One case I can think of, though haven't seen in the wild yet, is to abuse enums as a collection of disjointed integer constants:

enum somestuff { days_in_week = 7,
                 months_in_year = 12,
                 number_of_planets = 8,
                 fingers_per_hand = 5 };

The most pathological, innocent looking example I can imagine would be

enum numbers { one, two, three, four, five, six, seven, eight, nine, ten };

because one==0, two==1 etc.