(2014/04/07 14:27), Karl Tomlinson wrote:
> It is allowed in N3242. I think the relevant sections are
5.2.9 Static cast
Thank you for the pointer.
I found a floating copy of n3242.pdf at the following url.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
I think 7.2 10 is also relevant here.
--- quote ---
An expression of arithmetic or enumeration type can be converted to an
enumeration type explicitly. The
value is unchanged if it is in the range of enumeration values of the
enumeration type; otherwise the resulting
enumeration value is unspecified.
--- end quote
I take so :
typedef enum { a = 1, b, c = 10 } T;
T x;
x = 3; /* is OK it is within [1..10] although 3 is not in the list
explicitly */
but
x = 32; /*`unspecified' because it is outside [1..2^16] */
(I read the specification to mean
that the range of enumeration values is
[0 or 1 .. maximum_necessary_for_the_declared_maximum_value]
where maximum_necessary_for_the_declared_maximum_value is
the 2^M or (2^M-1) etc. depending on how the
negative value is represented. 2's complement or 1's complement.)
The description is very complex, but
it seems that the enumeration range be
calculated to produce the narrowest bit field that can contain
all the explicitly declared values (min .. max)
This is the range of values.
Anyway, in my example above, a compiler can do anything
if x = 32 is executed (?).
Hmm.I will re-read 7.2.7.
TIA
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform