Re: A question about sizeof, offsetof, new and objects in contiguous
regions. (Was Re: technical correctness 2)
On Jan 7, 5:59 am, LR <lr...@superlink.net> wrote:
Alf P. Steinbach /Usenet wrote:
It so happened that this vagueness (allowing non-contiguous regions)
was done deliberately in order to support multiple virtual
inheritance, but that at least some committee members saw it as not
only necessary for virtual inheritance, but also allowing
implementations that scatter parts of objects all around in memory.
Thus, the wording in the standard does not say right out that it's in
support of virtual inheritance. The standard intentionally leaves
the door open for what we'd now regard as "perverse" implementations.
:-)
Would I be correct in inferring that non-contiguous classes are no
longer regarded as necessary? If not, does the current draft still
support a requirement for this?
All of the implementations I know do insert extra bytes here and
there in the object; in this sense, they all use non-contiguous
memory.
The real question is: what did the authors of the standard mean
by "non-contiguous"? That parts of other objects are somehow
interspaced in the memory of the object. I don't think that
this could be made to work; how would operator new work, for
example. That not all of the memory encompassed in sizeof is
used by the object. That's the case, even in C, because padding
is not only allowed, but also necessary.
Did any implementation create objects with non-contiguous memory? Anyone
know?
However, in thread "Re: technical correctness"
in Message-ID: <AYqdnW1Lpptx9bnQnZ2dnUVZ8nydn...@bt.com>
Francis Glassborow <francis.glassbo...@btinternet.com>
wrote: "All subobjects must reside in a single contiguous region which
is the object. Otherwise sizeof and operator new would be useless:"
Would this also be a requirement for the offsetof macro as well? I
don't recall if offsetof is in the standard, but it is in n3126.
The macro offsetof is in the C++ standard, but it is restricted
to PODS.
--
James Kanze