Mail Archives: djgpp/1998/08/25/18:02:37
Thaks all folks for yours replies. Let me commnet them.
Ralph Gesler wrote:
< I don't know how the C standard defines the underlying type of
<enumeration, but in C++, which I suspect is compatable with C, it is
<implementation dependent. From the working papers of the C++ standard.
ANSI-C and C++ have some minor differences (r.18 in Stroustrup book 2nd
ed.) like sizeof( 'a' ) and the underlayed type for enum constants, they
are ints in ANSI-C.
Hans-Bernhard Broeker wrote:
<According to my understanding of the ANSI C standard, this is not a
<gcc bug, as this behaviour is left 'implementation-defined', there.
<To quote the ANSI C9x working draft:
<
< [#4] Each enumerated type shall be compatible with an
< integer type. The choice of type is implementation-defined,
< but shall be capable of representing the values of all the
< members of the enumeration.
<
<There's no word there about wether this integer type is signed or
<unsigned. It may even end up being an unsigned char, as long as that's
<big enough to hold all the tag values of the given enum. The
<enumeration constants themselves are a different issue: they are
<*ints*, always. But the enum type may be anything from char up to int,
<or maybe even long long int...
OK, if it's the ANSI-C paper (not C++), no more doubts. My wrong idea
was to suppose as enum constants are int, enum vars too.
Eli Zaretskii wrote:
<No, this is a bug in your program. K&R book notwithstanding, you
<cannot assume anything about how enums are implemented, unless you
<specify this to the compiler (see below). The ANSI C standard
<explicitly says that the representation of enum is
<implementation-defined.
<Moreover, you are NOT supposed to assign any value to the enum
<variable except those in the enum definition. In your case, you can
<nly assign V1, V2, or V3 to i; you cannot assign -1.
I disagree with you. I think is legal in ANSI-C and not C-compiler is
warning about. Nevertheless I will stop doing it.
Regards, M.Alvarez
- Raw text -