Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2002-12-04 16:32:31


David Abrahams <dave_at_[hidden]> writes:

| Gabriel Dos Reis <gdr_at_[hidden]> writes:
|
| > Thanks for your patience.
| >
| > Now, imagine an implementation where the original type is remembered,
| > then dereferencing the pointer obtained from
| >
| > char* -> void* -> T*
| >
| > may just eject you into the outer space.
|
| Is remembering the original type _of_ _the_ _pointer_ actually legal?

Why wouldn't it be valid for an implementation to remember the orginal
type of the object from which the pointer is obtained?

1.8/1
  [...] Some objects are polymorphic (10.3); the implementation
  generates information associated with each such object that makes it
  possible to determine that object s type during program
  execution. For other objects, the interpretation of the values found
  therein is determined by the type of the expressions (clause 5) used
  to access them.

Since an implementation is already required to generate information to
assist evaluations of polymorphic objects; what can't it do the same
for non-polymorphic objects, as an extension?

| Can you quote chapter and verse on this?

Since:

1.9/1
   [...] This International Standard places no requirement on the
   structure of conforming implementa-tions. [...]

you don't expect me to quote chapter and verse from the Standard; do you?
;-)

| I thought the implementation
| was only permitted to eject you if you use a pointer where the actual
| type _of_ _the_ _pointee_ is wrong.

  Undefined behavior may also be expected when this International
  Standard omits the description of any explicit definition of
  behavior.

There is no explicit description that after the trip

   char* -> void* -> Foo*

starting at h.storage, one can safely dereference the resulting
pointer.

-- Gaby


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