A
arnuld
after reading that sections, i know:
- an "enum" is user-defined type
- there is no implicit conversion from an "int" to an "enum" BUT an
"int" can be converted to an "enum" *explicitly*.
the thing i did not understand is the "range" of an "enum":
enum e1 { dark, light } // range 0:1
that is fine as dark == 0 and light == 1 (both are of type e1, not
"int")
enum e2 {a = 3, b = 9} // range 0:15
how come ? i think the range here is 0 - 9.
enum { min = -10, max = 1000000 } // range -1048576:1048575
hoe come here ?
Stroustrup also explained it:
"the range of an enumeration holds all the enumeration's enumerator
values rounded upto the nearest largest binary power minus 1. the
range goes down to zero if the smallest enumerator is non-negative and
nearest lesser negative binary power if the smallest enumeration is
negative. this defines the smallest bit-field capable of holding the
enumerator values."
so by this rule range of "e2" must be: 0 to 256 (which is 2^8,
because 9 -1 == 8)
i do not understand anything here :-(
even the last line is simply alien to me: "this defines the smallest
bit-field capable of holding the enumerator values"
what exactly is "bit-field" ?
- an "enum" is user-defined type
- there is no implicit conversion from an "int" to an "enum" BUT an
"int" can be converted to an "enum" *explicitly*.
the thing i did not understand is the "range" of an "enum":
enum e1 { dark, light } // range 0:1
that is fine as dark == 0 and light == 1 (both are of type e1, not
"int")
enum e2 {a = 3, b = 9} // range 0:15
how come ? i think the range here is 0 - 9.
enum { min = -10, max = 1000000 } // range -1048576:1048575
hoe come here ?
Stroustrup also explained it:
"the range of an enumeration holds all the enumeration's enumerator
values rounded upto the nearest largest binary power minus 1. the
range goes down to zero if the smallest enumerator is non-negative and
nearest lesser negative binary power if the smallest enumeration is
negative. this defines the smallest bit-field capable of holding the
enumerator values."
so by this rule range of "e2" must be: 0 to 256 (which is 2^8,
because 9 -1 == 8)
i do not understand anything here :-(
even the last line is simply alien to me: "this defines the smallest
bit-field capable of holding the enumerator values"
what exactly is "bit-field" ?