Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/articles/cpp-tutorials/)
-   -   Detail about How VPTR and Virtual table works (http://www.go4expert.com/articles/vptr-virtual-table-t8403/)

rahul.mca2001 6Mar2008 13:13

Re: Detail about How VPTR and Virtual table works
 
congrats sir

nerdpower 18Mar2008 21:46

Re: Detail about How VPTR and Virtual table works
 
This article is wrong ! The method the author describes only works for particular C++ compilers. Also the method used here is machine specific. The author has made assumptions on the size of the integer pointer which changes on different platforms. Its cool to tinker and find out how your compiler implements virtual function but this is not the same for all compilers and platforms.

There is **NOTHING** in the C++ Standard i.e. ISO/IEC 14882 (2003) that mentions how they are to be implemented. There are different ways to implementing virtual tables/pointers internally. If you want to understand how virtual functions (polymorphism) work pickup the ISO standard and start reading.

asadullah.ansari 19Mar2008 13:22

Re: Detail about How VPTR and Virtual table works
 
Quote:

Originally Posted by nerdpower
This article is wrong ! The method the author describes only works for particular C++ compilers. Also the method used here is machine specific. The author has made assumptions on the size of the integer pointer which changes on different platforms. Its cool to tinker and find out how your compiler implements virtual function but this is not the same for all compilers and platforms.

There is **NOTHING** in the C++ Standard i.e. ISO/IEC 14882 (2003) that mentions how they are to be implemented. There are different ways to implementing virtual tables/pointers internally. If you want to understand how virtual functions (polymorphism) work pickup the ISO standard and start reading.

I have already read the ISO standard, after reading i thought about it. I make it and test
on solaris system. This article gives you a idea about VPTR.

Can you tell me any compiler which is behaving different that whatever i descrived?
Offcourse compiler can implement any concept in different ways. Just go and read Iso standard for VPTR how it's designed?

alramesh 19Mar2008 17:52

Re: Detail about How VPTR and Virtual table works
 
Quote:

Originally Posted by nerdpower
This article is wrong ! The method the author describes only works for particular C++ compilers. Also the method used here is machine specific. The author has made assumptions on the size of the integer pointer which changes on different platforms. Its cool to tinker and find out how your compiler implements virtual function but this is not the same for all compilers and platforms.

There is **NOTHING** in the C++ Standard i.e. ISO/IEC 14882 (2003) that mentions how they are to be implemented. There are different ways to implementing virtual tables/pointers internally. If you want to understand how virtual functions (polymorphism) work pickup the ISO standard and start reading.


what's wrong. I got everything . I think you did'nt read c++ standard.

nerdpower 20Mar2008 14:57

Re: Detail about How VPTR and Virtual table works
 
Quote:

Originally Posted by alramesh
what's wrong. I got everything . I think you did'nt read c++ standard.

VPTR is nothing to do with the C++ Specification.

nerdpower 20Mar2008 15:09

Re: Detail about How VPTR and Virtual table works
 
Quote:

Originally Posted by asadullah.ansari
I have already read the ISO standard, after reading i thought about it. I make it and test
on solaris system. This article gives you a idea about VPTR.

Can you tell me any compiler which is behaving different that whatever i descrived?
Offcourse compiler can implement any concept in different ways.

http://www.thefreecountry.com/compilers/cpp.shtml

Are you sure that your explanation works for all these compilers?

IIRC, this wont work with MSVC. I have no problem with your explanation, you should mention that it will only work for x,y,z compiler under a,b,c platform. If you don't mention that, people reading your article will assume that this is a global standard for all C++ compilers.
Quote:

Originally Posted by asadullah.ansari
Just go and read Iso standard for VPTR how it's designed?

What ISO standard? Can you quote the actual standard that describes the size of vptr as 4 bytes? You can also define vtbl in different ways.

asadullah.ansari 20Mar2008 15:15

Re: Detail about How VPTR and Virtual table works
 
Quote:

Originally Posted by nerdpower
http://www.thefreecountry.com/compilers/cpp.shtml

Are you sure that your explanation works for all these compilers?

IIRC, this wont work with MSVC. I have no problem with your explanation, you should mention that it will only work for x,y,z compiler under a,b,c platform. If you don't mention that, people reading your article will assume that this is a global standard for all C++ compilers.

Can you quote the actual standard that describes the size of vptr as 4 bytes? You can also define vtbl in different ways.



i have mention above it's for 32 bit machine

talk2mohdsaif 13Nov2009 17:38

Re: Detail about How VPTR and Virtual table works
 
Very Nice artical bro..........................

talk2mohdsaif 15Nov2009 18:03

Re: Detail about How VPTR and Virtual table works
 
really nice article..
i was confusion in vtable but now i know all about vtable and vptr.......


All times are GMT +5.5. The time now is 19:53.