Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2002-12-05 07:50:03


Anthony Williams <anthony.williamsNOSPAM_at_[hidden]> writes:

| > Anthony Williams <anthony.williamsNOSPAM_at_[hidden]> writes:
| >
| > [...]
| >
| > | 3.10p15:
| > | "If a program attempts to access the stored value of an object through an
| > | lvalue of other than one of the following types the behavior is undefined:
| > |
| > | - the dynamic type of the object,
| > |
| > | ...
| > |
| > | - a char or unsigned char type."
| > |
| > | So given a Foo object foo, static_cast<char*>(static_cast<void*>(&foo)) is
| > | legal, and can be used to access the object representation of the object.
| >
| > There is no question that the above cast is legal. I thin the issue
| > is elsewhere. The key question is whether that may be different from
| >
| > reinterpret_cast<void*>(&foo);
|
| I thought the issue was whether the pair of static_cast<>s in dangerous_cast<>
| was as implementation defined as a reintepret_cast<> would be. If you read my
| mail to the end, hopefully I have explained that I think that the
| static_cast<> pair is legal and well-defined, as opposed to using
| reinterpret_cast, which is implementation-defined. If I haven't made myself
| clear, I apologise, and will try again.

You made youself clear.

However, there are two running issues originating from a claim of Dave
that dangerous_cast<> might be better than reinterpret_cast<> in
casting from U* to T* (dangerous_cast<> uses the intermediate step
void* via static_cast<>).

  1) is dangerous_cast<> better than reinterpret_cast<>?

  2) is it well-defined to dereference the value obtained from

       U* -> void* -> T*
    
     ?

You've showed that si U == char, (the case in Dave's example) then it
is well-formed. The other cases are left undefined.

So the key question (1) is still unanswered.

-- Gaby


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