[dcl.enum]
"For an enumeration whose underlying type is not fixed, the values of the enumeration are the values of the underlying type in the range b{min} to b{max}, where b{min} and b{max} are, respectively, the smallest and largest values of the smallest bit-field that can store the values of the enumerators."
How the Range is Calculated
The standard uses a "smallest bit-field" logic (powers of two) to determine valid values:
Find the Min/Max labels: Let e{min} be the smallest enumerator and e{max} be the largest.
- Determine the Range:If e{min} >= 0
- The range is [0, 2^k - 1], where 2^k is the smallest power of two such that e{max} < 2^k.
- If e{min} < 0
- The range includes negative numbers, typically corresponding to a signed bit-field (two's complement). The range is [-2^k, 2^k - 1].
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.