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?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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:
The most pathological, innocent looking example I can imagine would be
The biggest issue I've had with enumerations is them being defined twice.
and someone else, with a very similar name, would have
It's not a "quick catch" because that's the enum you made.. right? It's something you don't really see until you're stepping through the code and see that your 'No' is coming back as zero instead of one.
In C++ (would have posted as comment, but for the code this works better)
Another applicaiton would be qualifiers:
I'm still undecided if this is wickedly cool, wickedly horrible, or both. (Wouldn't use that in production code, for that reason).