Gabriel Dos Reis <[EMAIL PROTECTED]> writes:

> David Abrahams <[EMAIL PROTECTED]> writes:
>
> | "Eric Woodruff" <[EMAIL PROTECTED]> writes:
> | 
> | > "David B. Held" <[EMAIL PROTECTED]> wrote in message
> | > aslftb$cr2$[EMAIL PROTECTED]">news:aslftb$cr2$[EMAIL PROTECTED]...
> | >> "Eric Woodruff" <[EMAIL PROTECTED]> wrote in message
> | >> aslbsn$nt3$[EMAIL PROTECTED]">news:aslbsn$nt3$[EMAIL PROTECTED]...
> | >> > [snip]
> | >> >
> | >> > > holder<Foo> h;
> | >> > > new (h.storage) Foo;
> | >> >
> | >> > What is the meaning of that syntax?
> | >>
> | >> This is placement new syntax.  It means construct a Foo at the address
> | >> h.storage, without allocating any memory.
> | >>
> | >
> | > So the type really is of Foo, which has to mean that casting h.storage back
> | > to a Foo* using reinterpret_cast is covered by the standard.
> | 
> | No, the standard only guarantees that you can do a round-trip
> | cast. The pointer didn't start out as a Foo*. The fact that it has the
> | same address as a Foo* doesn't mean anything. Just for example,
> | something like the following is a perverse but legal reinterpret_cast
> | implementation:
> | 
> |      if is_pointer<source_type> and is_pointer<dest_type>
> |         return (dest_type)(
> |                  (unisgned)src
> |                         ^ sizeof(remove_pointer<source_type>::type)
> |                          ^ sizeof(remove_pointer<dest_type>::type));
>
> And why isn't that applicable to the trip
>
>     char* -> void* -> Foo*

You mean aside from the fact that sizeof(void) is illegal? ;-)

If the implementation is such that the same bit pattern must be used
to reference a given address, using reinterpret_cast would do
something like

p ^ sizeof(char) ^ sizeof(void) ^ sizeof(void) ^ sizeof(Foo)

and, assuming sizeof(void) is well-defined the resulting pointer would
have been xor'ed with sizeof(char) and sizeof(Foo), so it would point
into outer space.

or-some-equally-useful-place-ly y'rs,
-- 
                       David Abrahams
   [EMAIL PROTECTED] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to