Article View: comp.std.c++
Article #3866Re: Enumerated type converted to pointer? Legal?
From: J. Kanze
Date: Sat, 30 Mar 1996 05:38
Date: Sat, 30 Mar 1996 05:38
46 lines
3009 bytes
3009 bytes
In article <315a9640.1061096@news.ultranet.com>
phalpern@truffle.ultranet.com (Pablo Halpern) writes:
|> kanze@gabi-soft.fr (J. Kanze) wrote:
|> >The error may be historically conditioned. As I interpret the C
|> >standard, an enumerated constant has type int, and a constant integral
|> >expression which evalutates to 0 is a null pointer. Even in the ARM,
|> >however, ``An enumeration is a distinct integral type.''
|> That begs the question, however, whether being an integral type with
|> constant value zero is sufficient to allow assignment to a pointer.
|> Is this legal? I believe all of the above is legal, though IMO it
|> shouldn't be (see below)
|> enum ptrNil { nil3 };
|> void *p = nil3;
|> You are claiming that this is not legal because nil3 is of type ptrNil
|> which is not compatable with the type of p. However, I fail to see how
|> nil3 is different from nil1 and nil2 in this respect. All are `integral'
|> types with value zero.
Before going any farther, several people have already pointed out my
mistake to me in private email. Basically, I missed the fact that when
enum's were made full types, the definition of integral constant was
also extended to include them. So the above is legal, and nil3 is a
legal null pointer. (In C, it was definitly legal, because the type of
nil3 was expressedly int. I mistakenly supposed that because C++
changed this type, it had also rendered the above illegal.)
I, for one, wouldn't object if the definition of a null pointer were
further restricted to limit it to only {int, unsigned int, long,
unsigned long}.
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Technical Details
Message-ID:
<KANZE.96Mar29115450@gabi.gabi-soft.fr>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<4hobji$mco@netlab.cs.rpi.edu> <KANZE.96Mar22115626@gabi.gabi-soft.fr> <315a9640.1061096@news.ultranet.com>Show Full Headers
Complete Article Headers
From: kanze@gabi-soft.fr (J. Kanze) Message-ID: <KANZE.96Mar29115450@gabi.gabi-soft.fr> X-Original-Date: 29 Mar 1996 10:54:50 GMT Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 30 Mar 96 05:38:06 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Enumerated type converted to pointer? Legal? Organization: GABI Software, Sarl. References: <4hobji$mco@netlab.cs.rpi.edu> <KANZE.96Mar22115626@gabi.gabi-soft.fr> <315a9640.1061096@news.ultranet.com> In-Reply-To: phalpern@truffle.ultranet.com's message of 28 Mar 96 13:59:51 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMVzIzOEDnX0m9pzZAQGgzAGAiqn0Bd2oq1hbCznxH2C9BZiucYUkG7vL r74Hyxcc1N6qqjAaqlwk/s3fy8qHNyC+ =2Sok