Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2002-12-04 15:33:46


"Peter Dimov" <pdimov_at_[hidden]> writes:

| From: "Gabriel Dos Reis" <gdr_at_[hidden]>
| > David Abrahams <dave_at_[hidden]> writes:
| >
| > | Gabriel Dos Reis <gdr_at_[hidden]> writes:
| > |
| > | > Hmm, I have a couple of questions answers to which will help me
| > | > get your point.
| > | >
| > | > 1) Why can't you do that with reinterpret_cast?
| > |
| > | You can, but the results are non-portable
| >
| > No more non-portable than with dangerous_cast<>.
|
| I think that Dave's point is that in
|
| new(h.storage) Foo;
|
| there is a char* -> void* implicit conversion as placement new takes a
| void*. So the placement new performs char* -> void* -> Foo* (by constructing
| a Foo at (void*)h.storage), which - in theory - might not be the same as
| char* -> Foo*.

But then, that theoretical implementation can remember the type from
which the conversion to void* was made and may issue an error when an
attempt is made to dereference the pointer obtained by recasting the
result of static_cast<void*>(h.storage) to Foo*.

Practical notes:
Historically, char* was used as the type of "raw memory" until "void*"
was invented. And since then char* and void* continues to have the
same properties as raw-memory issues are concerned.

-- Gaby


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