Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2005-09-17 12:48:49


Adam Badura wrote:
> At first english is not my primary language and all my books on C++ are
> in polish so I have to translate. I'm afraid I'm not using correct words or
> terms but I will try to be as descripting as possible to be understood.
>
> I have a question on placement of subobjects in a class (or struct -
> what I know of standard this will be the same). In S. Lippman's "Inside the
> C++ Object Model" I found that standard only guaranties that subobjects are
> placed in specific sequence (not to get inside details) but there is no
> guarante that compiler doesn't place some additional objects (for his
> internal use) at the begining of object in between subobjects or at the end.
> (I looked also in Stroustrup's "The C++ Programming Language" and "The
> Design and Evolution of C++" but have found nothing - but I wasn't looking
> that hard).
>
> So, if I have a class:
>
> class point2d {
> public:
> double x;
> double y;
> };
>
> and make an object of it
>
> point2d pp = new point2d;

point2d * pp = new point2d;

>
> than ther is no guaranty that
>
> reinterpret_cast<double*>(pp) will give me addres of point2d::x.

Correct. But many compilers allow you to specify a packing which can
ensure that your expression will work as specified. That is compiler
specific but nor part of the C++ standard.


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