Range of an enumeration...

This is a discussion on Range of an enumeration... within the C++ Programming forums, part of the General Programming Boards category; I need an explination of this:
..." The range of an enumeration holds all the enumeration's enumerator values rounded up ...

the size of the enumeration MUST be big enough to contain highest value of the enumeration, in this case it must be 4 (since INVALID == 4), and it must be a value that is a power of 2, minus 1.

So for us to be able to store the value 4, the enumeration must be a power of 2 minus one that is bigger or equal to 4.. in this case that's 2^3 - 1 = 8 - 1 = 7. So this enumeration can store from 0-7 (not just the 0-4 that we need).

If you had:
enum { IDLE = 23, STARTING, RUNNING, ENDING, INVALID };

then the enumeration would need to hold a max value of 27, the nearest power of two minus one is 31... so the size of the enumeration would be 31.