Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Getting add...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 8 Topic 9511 of 9775
Post > Topic >>

Re: Getting address of enclosing object from address of inner object

by courpron@[EMAIL PROTECTED] Apr 21, 2008 at 04:13 PM

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! ]
 




 8 Posts in Topic:
Getting address of enclosing object from address of inner object
xtrigger303@[EMAIL PROTEC  2008-04-17 03:58:28 
Re: Getting address of enclosing object from address of inner ob
Lance Diduck <lancedid  2008-04-17 12:01:26 
Re: Getting address of enclosing object from address of inner ob
Greg Herlihy <greghe@[  2008-04-17 16:22:29 
Re: Getting address of enclosing object from address of inner ob
courpron@[EMAIL PROTECTED  2008-04-17 16:20:23 
Re: Getting address of enclosing object from address of inner ob
xtrigger303@[EMAIL PROTEC  2008-04-18 17:16:35 
Re: Getting address of enclosing object from address of inner ob
courpron@[EMAIL PROTECTED  2008-04-19 18:15:05 
Re: Getting address of enclosing object from address of inner ob
xtrigger303@[EMAIL PROTEC  2008-04-21 10:26:26 
Re: Getting address of enclosing object from address of inner ob
courpron@[EMAIL PROTECTED  2008-04-21 16:13:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:42:27 CDT 2008.