Thread View: comp.std.c++
2 messages
2 total messages
Started by Bernd Anhaeupl
Sat, 06 Apr 1996 19:32
dynamic_cast<void*>
Author: Bernd Anhaeupl
Date: Sat, 06 Apr 1996 19:32
Date: Sat, 06 Apr 1996 19:32
92 lines
3769 bytes
3769 bytes
Section 5.2.6 paragraph 7 of the April 95 WP states, that for
polymorphic types, the result of a dynamic_cast<void*>(v) "is a
pointer to the complete object (12.6.2) pointed to by v". Now
section 12.6.2 does not define the term "complete object", which
actually happens in section 1.4 paragraph 2, but the term
"most derived class". This makes a differnce, if we pass a pointer
to a data member subobject (and not a base class subobject) to
dynamic_cast. According to 12.6.2, we would get the address of that
data member, according to 1.4, the address of the containing
object of that data member.
Please note, that the term "complete object (12.6.2)" is also used
in section 5.2.7, where the typeid expression is defined. Therefore
I suppose, that in 5.2.6 and 5.2.7 "most derived object" is meant
instead of "complete object" in both sections. Is this correct?
Example:
#include <typeinfo>
#include <iostream>
class foo1{
public:
foo1(){};
virtual ~foo1(){}
};
class foo2{
public:
foo2(){};
virtual ~foo2(){}
};
class bar:public foo1, public foo2{
public:
foo1 f1m;
foo2 f2m;
bar(){};
virtual ~bar(){}
};
int main()
{
bar b;
foo1 & f1=b;
foo2 & f2=b;
foo1 & f1m=b.f1m;
foo2 & f2m=b.f2m;
cout << " &b == " << &b
<< " dynamic_cast<void*>( &b) == " << dynamic_cast<void*>(&b) << endl;
cout << " &f1 == " << &f1
<< " dynamic_cast<void*>( &f1) == " << dynamic_cast<void*>(&f1) << endl;
cout << " &f2 == " << &f2
<< " dynamic_cast<void*>( &f2) == " << dynamic_cast<void*>(&f2) << endl;
cout << "&f1m == " << &f1m
<< " dynamic_cast<void*>(&f1m) == " << dynamic_cast<void*>(&f1m) << endl;
cout << "&f2m == " << &f2m
<< " dynamic_cast<void*>(&f2m) == " << dynamic_cast<void*>(&f2m) << endl;
return 0;
}
Interpreting 5.2.6 in the sense of "most derived object" would yield
something like (at least gcc 2.7.0 does it in this way)
&b == 0xbffffaa8 dynamic_cast<void*>( &b) == 0xbffffaa8
&f1 == 0xbffffaa8 dynamic_cast<void*>( &f1) == 0xbffffaa8
&f2 == 0xbffffaac dynamic_cast<void*>( &f2) == 0xbffffaa8
&f1m == 0xbffffab0 dynamic_cast<void*>(&f1m) == 0xbffffab0
&f2m == 0xbffffab4 dynamic_cast<void*>(&f2m) == 0xbffffab4
where "complete object" should result in
&b == 0xbffffaa8 dynamic_cast<void*>( &b) == 0xbffffaa8
&f1 == 0xbffffaa8 dynamic_cast<void*>( &f1) == 0xbffffaa8
&f2 == 0xbffffaac dynamic_cast<void*>( &f2) == 0xbffffaa8
&f1m == 0xbffffab0 dynamic_cast<void*>(&f1m) == 0xbffffaa8
&f2m == 0xbffffab4 dynamic_cast<void*>(&f2m) == 0xbffffaa8
--
Bernd Anhaeupl Tel.: +49 9131 857787
LATE - Uni Erlangen
Cauerstr. 7 Email: anhaeupl@late.e-technik.uni-erlangen.de
91058 Erlangen
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Re: dynamic_cast<void*>
Author: Fergus Henderson
Date: Mon, 08 Apr 1996 09:03
Date: Mon, 08 Apr 1996 09:03
37 lines
2420 bytes
2420 bytes
anhaeupl@late.e-technik.uni-erlangen.de (Bernd Anhaeupl) writes: >Section 5.2.6 paragraph 7 of the April 95 WP states, that for >polymorphic types, the result of a dynamic_cast<void*>(v) "is a >pointer to the complete object (12.6.2) pointed to by v". Now >section 12.6.2 does not define the term "complete object", which >actually happens in section 1.4 paragraph 2, but the term >"most derived class". This makes a differnce, if we pass a pointer >to a data member subobject (and not a base class subobject) to >dynamic_cast. According to 12.6.2, we would get the address of that >data member, according to 1.4, the address of the containing >object of that data member. > >Please note, that the term "complete object (12.6.2)" is also used >in section 5.2.7, where the typeid expression is defined. Therefore >I suppose, that in 5.2.6 and 5.2.7 "most derived object" is meant >instead of "complete object" in both sections. Is this correct? Yes. The term "complete object" was used to mean two different things by different members of the C++ committee; one of those meanings is what is now called "most derived object". This error has been corrected in the Jan 96 draft, both in 5.2.6 and in 5.2.7. -- Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit" PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp. --- [ 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 ] [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ] [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ] [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads