Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2002-12-04 14:25:59


David Abrahams <dave_at_[hidden]> writes:

| "Eric Woodruff" <Eric.Woodruff_at_[hidden]> writes:
|
| > "David B. Held" <dheld_at_[hidden]> wrote in message
| > news:aslftb$cr2$1_at_main.gmane.org...
| >> "Eric Woodruff" <Eric.Woodruff_at_[hidden]> wrote in message
| >> news:aslbsn$nt3$1_at_main.gmane.org...
| >> > [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*

?

-- Gaby


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk