From: Anthony Williams (anthony.williamsNOSPAM_at_[hidden])
Date: 2002-12-05 11:41:24


Eric Woodruff writes:
> "Anthony Williams" <anthony.williamsNOSPAM_at_[hidden]> wrote in
> message news:15855.9421.560000.173275_at_gargle.gargle.HOWL...
> > Thus, given that h.storage is properly aligned, (which is the purpose of
> the
> > other union member), after "new(h.storage) Foo", h.storage contains a Foo
> > object. Thus accessing it through a pointer-to-Foo is legal, as Foo is the
> > dynamic type of the object.
> >
>
> This is precisely my reasoning why reinterpret_cast<> is _not_
> implementation defined.
>
> It must be the case that it is equal to the situation of having
>
> Foo* -> char */void* -> Foo* if Foo is the dynamic type of the object.

Nowhere do I see a requirement that supports your deductions. Indeed there are
very few requirements on reinterpret_cast<>, other than the fact that what it
does must be defined by the implementation. For pointers to objects, these
amount to:

* T1* can be converted to T2* and back again unchanged (unless T2 has stricter
  alignment requirements).

* You can convert a pointer to the first member of a POD struct to a pointer
  to the struct, and vice-versa.

* A Null pointer of any type can be cast to a null pointer of any other type.

Anthony

-- 
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.