Article View: comp.std.c
Article #2902Re: Compatability of enum types and integer types
From: Jerry Schwarz
Date: Tue, 22 Dec 1992 20:39
Date: Tue, 22 Dec 1992 20:39
47 lines
1825 bytes
1825 bytes
In article <1992Dec21.225604.18749@netcom.com>, rfg@netcom.com (Ronald F. Guilmette) writes:
|> The ANSI C standard says (in 3.5.2.2):
|>
|> "Each enumerated type shall be compatible with an integer type;
|> the choice of type is implementation-defined."
|>
|> I am having a polite disagreement with one implementor regarding the
|> proper interpretation of this statement.
|>
|> I interpret it to mean that there *must* exist some integer type `T'
|> such that:
|>
|> enum E { red, green, blue };
|>
|> enum E object;
|> T object;
|>
|> enum E *ptr;
|> T *ptr;
|>
|> ... is a valid translation unit.
It requires more for
enum E object ;
int object ;
to be legal than that E and int be compatible. 3.1.2.6
says that the "type of the identifier becomes the composite type".
It also gives the rules for determining a composite type and
says nothing about combining enums and integer types. Granted,
this isn't a constraint section, but if there isn't a composite
type then I think the compiler is justified in treating the above
as an error.
[Maybe I'm stretching. I feel strongly that the above ought
to be an error and I went looking for a way to make it so. I'm
assuming that the original x3j11 committee didn't intend to force
us to accept code like the above, but I wasn't a member.]
-- Jerry Schwarz
-- Jerry Schwarz
Technical Details
Message-ID:
<1992Dec22.203938.29580@lucid.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!lucid.com!lucid.com!jssReferences:
<1992Dec21.225604.18749@netcom.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!lucid.com!lucid.com!jss From: jss@lucid.com (Jerry Schwarz) Subject: Re: Compatability of enum types and integer types Message-ID: <1992Dec22.203938.29580@lucid.com> Sender: usenet@lucid.com Reply-To: jss@lucid.com (Jerry Schwarz) Organization: Lucid, Inc. References: <1992Dec21.225604.18749@netcom.com> Date: Tue, 22 Dec 92 20:39:38 GMT Lines: 47