Topic: Discontiguous objects (was Why don't constructors and destructors have return types?)
Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Sat, 13 Jul 2002 16:38:14 GMT Raw View
On Fri, 12 Jul 2002 16:11:36 GMT, jpotter@falcon.lhup.edu (John
Potter) wrote:
>On 12 Jul 2002 02:58:39 GMT, Gennaro Prota <gennaro_prota@yahoo.com>
>wrote:
>
>> Well, tell me what does discontiguous mean (Please, don't think I'm
>> quibbling: I really believe that this kind of discussion do NEED
>> robust definitions).
>
>Let me change all types to int so that we can avoid padding.
>
>> For example (James Kanze's code):
>
>> struct VB { char vbi ; } ;
>
>> struct B : virtual VB { char bi ; } ;
>
>> struct C : virtual VB { char ci ; } ;
>
>> struct D : B, C { int di ; } ;
>
>> int main() {
>> D d ;
>> std::cout << "sizeof B = " << sizeof( B ) << '\n' ;
>> std::cout << "distance between bi and vbi = "
>> << &d.vbi - &d.bi << '\n' ;
>
> B b;
> std::cout << "distance between bi and vbi = "
> << &b.vbi - &b.bi << "\n";
>
>> return 0 ;
>> }
>
>The two outputs may be different.
>
>> This code accesses two sub-objects of D. None of them is the VB
>> subobject. You cannot name that subobject. So how does this
>> demonstrate that it is discontiguous?
>
>It is not VB. A possible layout which happens on my compiler.
>
>D B 00 virtual base pointer
> 04 bi
> C 08 another virtual base pointer
> 0C ci
> 10 di
> VB 14 vbi
>
>Both virtual base pointers point to VB. Both the B and C base
>subobjects are discontiguous. They do not have object representations
>because they are not sequences of bytes.
>
>Your DR in work says that sizeof only applies to complete objects. It
>still applies to all subobjects except base subobjects. For example,
>sizeof(d.di) in the above is still four.
That's because you probably skipped the DR and only read my short
explanation at the end, where I was not able to rephrase my own words
:-)
If you look above you will see that part a) says that member
sub-objects of type T have size sizeof (T).
Also, if it is clearer for you, I could reformulate the statement in
b) as:
"The sizeof operator yields the number of bytes in the object
representation of [its operand -> a _non base sub-object_ object whose
type is determined by its operand]."
>
>My solution is to note that the B subobject of D does not have a name
>and does not have a type B object representation and conclude that it
>is not an object of type B but an object of type B subobject of D.
>
>You have a DR, I have a rationalization. Mine requires no processing
>by the committee. Best wishes with yours.
Looks like you begin to be irritated. I'm sorry for that, but I was
only asking for some explanation about your point of view.
Indeed, I was already incline to think that yours was a reasonable
interpretation (As I said, my dr rationalized *part* of the issue and
is based on the maybe erroneous assumption that any object has a
representation).
But I'm also convinced that if it was not what the committee had in
mind, and if they didn't adopted a more than careful language to deal
with this idea that the type of a base sub-object of class B has not
type B, then problems would spring up like mushrooms.
10/5 for instance has a note that talks repeatedly about "same type".
Yes, it a note. But if this was the idea...
Genny.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: Fri, 12 Jul 2002 16:11:36 GMT Raw View
On 12 Jul 2002 02:58:39 GMT, Gennaro Prota <gennaro_prota@yahoo.com>
wrote:
> Well, tell me what does discontiguous mean (Please, don't think I'm
> quibbling: I really believe that this kind of discussion do NEED
> robust definitions).
Let me change all types to int so that we can avoid padding.
> For example (James Kanze's code):
> struct VB { char vbi ; } ;
> struct B : virtual VB { char bi ; } ;
> struct C : virtual VB { char ci ; } ;
> struct D : B, C { int di ; } ;
> int main() {
> D d ;
> std::cout << "sizeof B = " << sizeof( B ) << '\n' ;
> std::cout << "distance between bi and vbi = "
> << &d.vbi - &d.bi << '\n' ;
B b;
std::cout << "distance between bi and vbi = "
<< &b.vbi - &b.bi << "\n";
> return 0 ;
> }
The two outputs may be different.
> This code accesses two sub-objects of D. None of them is the VB
> subobject. You cannot name that subobject. So how does this
> demonstrate that it is discontiguous?
It is not VB. A possible layout which happens on my compiler.
D B 00 virtual base pointer
04 bi
C 08 another virtual base pointer
0C ci
10 di
VB 14 vbi
Both virtual base pointers point to VB. Both the B and C base
subobjects are discontiguous. They do not have object representations
because they are not sequences of bytes.
Your DR in work says that sizeof only applies to complete objects. It
still applies to all subobjects except base subobjects. For example,
sizeof(d.di) in the above is still four.
My solution is to note that the B subobject of D does not have a name
and does not have a type B object representation and conclude that it
is not an object of type B but an object of type B subobject of D.
You have a DR, I have a rationalization. Mine requires no processing
by the committee. Best wishes with yours.
John
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]