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 7 of 8 Topic 9511 of 9823
Post > Topic >>

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

by xtrigger303@[EMAIL PROTECTED] Apr 21, 2008 at 10:26 AM

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.
And I'm confused by the statement that compilers might rearrange
members...
Let's suppose I have the following memory layout for objects A, B and
C.


A memory layout
________________________________________
0 - A::member1 <- address of objectA
1 - A::XXXX
2 - A::member2
________________________________________

In this case if I have an object A and the offset to XXXX (suppose 1 )
I can get
back to the address of A.

//

B: virtual A
________________________________________
0 - VPTR <- address of objectB
________________________________________
1 - A::member1 <- address of (A*)(&objectB)
2 - A::XXXX
3 - A::member2
________________________________________
4 - B::member1
________________________________________

In this case I still have the address of XXX and I want to get to the
address of
(A*)(&objectB). This means I want to get from 2 to 1, not from 2 to 0.
I understand that the compiler might put B members before or after A
members
but I don't think it can rearrange the members inside of A.

//

C: B, virtual A
________________________________________
0 - VPTR <- address objectC and (B*)(&objectC)
________________________________________
1 - A::member1 <- address of (A*)(&objectC)
2 - A::XXXX
3 - A::member2
________________________________________
4 - B::member1
________________________________________
5 - C::member1
6 - C::member2
________________________________________

Same thing as above if I have the address of XXXX I think I still can
get reliably
to the address of the enclosed A. That is from 2 to 1. I understand
that going from
2 to 0 would be unreliable. Since I cannot be sure that relative
position of
A members, B members and C members are in this way or another.

Thanks again,
Francesco

-- 
      [ 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 Thu Jul 24 1:35:59 CDT 2008.