On Apr 21, 6:26 pm, xtrigger...@[EMAIL PROTECTED]
wrote:
> Hi and thanks again for answering.
> You gents have convinced me is not the path to follow.
> I'm proceeding in a different direction.
> But by looking at Alexandre's example I thing you've misunderstood my
> intentions.
I think I understood your intentions. My example is merely
illustrating the member reordering side-effects.
I said that if you don't care at all about the dynamic type of the
object your are working on [ that is to say if, for the latter, static
type == dynamic type ], then it may work in practice, although such
behavior is not described explicitly by the C++ standard.
In your first message, you didn't state that you would always work on
non-polymorphic objects, so we were saying that it is not reliable to
use the offset of a member of a non-POD class. Then I explained this
*original* statement with the example of the member reordering part of
some implementations of multiple and virtual inheritance, followed by
a code example.
> And I'm confused by the statement that compilers might rearrange
> members...
It would be pretty long to explain how a compiler could implement
multiple and virtual inheritance. I found a link that explains pretty
clearly such implementation :
http://www.phpcompiler.org/doc/virtualinheritance.html
>
> Memory layout examples [ ... ]
>
In your examples, you want the address of the sub-object "A" which is
of course always non-polymorphic. If you wanted the address of an
object such as : A* object = new C();
then getting it from the offset of a member in "A" wouldn't have been
reliable. Since, you stated in your second post that it won't be the
case, then I answered "it may work in practice (c)".
Alexandre Courpron.
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|