From -5106815708854372396
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,11af4794c44339e8
X-Google-Attributes: gidf78e5,public
From: jpotter@falcon.lhup.edu (John Potter)
Subject: Re: Can you static_cast between enums?
Date: 1999/12/20
Message-ID: <385c3972.111450192@news.csrlink.net>#1/1
X-Deja-AN: 563001766
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <ktA14.377$6A5.16841@dfiatx1-snr1.gtei.net> <832fub$t0$1@news.hamburg.pop.de> <385AA7AA.8D983B3@tribble.com> <83gnm6$u1f$1@nnrp1.deja.com>
X-Original-Date: 18 Dec 1999 19:49:01 -0600
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: ariel.ucs.unimelb.edu.au 945700268 5094 128.250.37.153 (20 Dec 1999 14:31:08 GMT)
Organization: Newscene Public Access Usenet News Service (http://www.newscene.com/)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAOF49yeEDnX0m9pzZAQHq2QF/R3tM2pvw8Wc/QlCqPF2MyGXiwKS4j1Gs h7j8YD8T4Sv0IHn9BPrCi3p+mgr0/Toy =Mryw
NNTP-Posting-Date: 20 Dec 1999 14:31:08 GMT
Newsgroups: comp.std.c++

On 18 Dec 1999 23:24:34 GMT, wmm@fastdial.net wrote:

: 
: In article <385AA7AA.8D983B3@tribble.com>,
:   David R Tribble <david@tribble.com> wrote:
: > So what does the following expression do, in terms of the xxx_cast
: > operators?
: >
: >     enum Color { RED, WHITE, BLUE };
: >     enum Hue { R, W, B };
: >
: >     Hue  h = (Hue)RED;   // not static_cast<Hue>(RED)?
: 
: None of the casting mechanisms -- "(Hue)RED", "Hue(RED)", and
: "static_cast<Hue>(RED)" -- allows this conversion, according to
: the current wording of the standard.  As I said earlier in this
: thread, this is an oversight and is expected to be corrected in
: the first Technical Corrigendum.

        Hue h(static_cast<Hue>(static_cast<int>(RED)));

is a bit messy.  Is the following also an oversight?

   struct S { int x, y };

   S s;
   int* p(static_cast<int*>(static_cast<void*>(&S)));

We are assured that the address of the struct may be cast to the
address of the first element; however, it must either be an
implementation defined reinterpret_cast or a double cast with no
assurances that it will work.  5.2.9/10 does not say "except that"
like 5.2.10/*, but seems to make it questionable.

John
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



