![]() |
Is the vptr at the beginning of an object?
In practice, across most compilers, is the vptr at offset 0 of a class
object? I've found some posts that say GCC puts it at the end, but they were very old posts and I don't use it now so can't test it. |
Re: Is the vptr at the beginning of an object?
On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote:
> In practice, across most compilers, is the vptr at offset 0 of > a class object? I've found some posts that say GCC puts it at > the end, but they were very old posts and I don't use it now > so can't test it. Who cares? What does it matter where the vptr is placed? (And of course, many objects have more than one vptr, and not all of them can be at offset 0.) -- James Kanze |
Re: Is the vptr at the beginning of an object?
On 2 Apr, 11:07, James Kanze <james.ka...@gmail.com> wrote:
> On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote: > > > In practice, across most compilers, is the vptr at offset 0 of > > a class object? I've found some posts that say GCC puts it at > > the end, but they were very old posts and I don't use it now > > so can't test it. > > Who cares? *What does it matter where the vptr is placed? *(And > of course, many objects have more than one vptr, and not all of > them can be at offset 0.) Just out of curiosity, I thought the compiler was obliged to put the first member at offset zero? If so (and it could well be I'm wrong here...) then it must put the vptr (assuming there is one) somewhere else? |
Re: Is the vptr at the beginning of an object?
* Paul N:
> On 2 Apr, 11:07, James Kanze <james.ka...@gmail.com> wrote: >> On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote: >> >>> In practice, across most compilers, is the vptr at offset 0 of >>> a class object? I've found some posts that say GCC puts it at >>> the end, but they were very old posts and I don't use it now >>> so can't test it. >> Who cares? What does it matter where the vptr is placed? (And >> of course, many objects have more than one vptr, and not all of >> them can be at offset 0.) > > Just out of curiosity, I thought the compiler was obliged to put the > first member at offset zero? Only for a POD. For a POD it's guaranteed by reinterpret_cast to suitable type yielding a pointer to the first member (and vice versa). > If so (and it could well be I'm wrong > here...) then it must put the vptr (assuming there is one) somewhere > else? When the first data member is at offset 0 a vptr, if the implementation uses that scheme (but all do), must be put somewhere else, yes. Generally this is only relevant when considering binary layout compatibility. However, the language supports compilers that put a vpointer at offset 0, e.g. when introducing a virtual member function in a derived class, because given a pointer to some class type object a static_cast up or down an inheritance chain can change the pointer value as given by a conversion to void*. Cheers & hth., - Alf |
Re: Is the vptr at the beginning of an object?
James Kanze wrote:
> On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote: >> In practice, across most compilers, is the vptr at offset 0 of >> a class object? I've found some posts that say GCC puts it at >> the end, but they were very old posts and I don't use it now >> so can't test it. > > Who cares? What does it matter where the vptr is placed? (And > of course, many objects have more than one vptr, and not all of > them can be at offset 0.) If you couldn't answer the question asked, you shouldn't have bothered posting! |
Re: Is the vptr at the beginning of an object?
On 04/ 3/10 12:16 AM, DaveB wrote:
> James Kanze wrote: >> On Apr 2, 9:56 am, "DaveB"<DBu...@usenet.net> wrote: >>> In practice, across most compilers, is the vptr at offset 0 of >>> a class object? I've found some posts that say GCC puts it at >>> the end, but they were very old posts and I don't use it now >>> so can't test it. >> >> Who cares? What does it matter where the vptr is placed? (And >> of course, many objects have more than one vptr, and not all of >> them can be at offset 0.) > > If you couldn't answer the question asked, you shouldn't have bothered > posting! He did answer the question! -- Ian Collins |
Re: Is the vptr at the beginning of an object?
Ian Collins wrote:
> On 04/ 3/10 12:16 AM, DaveB wrote: >> James Kanze wrote: >>> On Apr 2, 9:56 am, "DaveB"<DBu...@usenet.net> wrote: >>>> In practice, across most compilers, is the vptr at offset 0 of >>>> a class object? I've found some posts that say GCC puts it at >>>> the end, but they were very old posts and I don't use it now >>>> so can't test it. >>> >>> Who cares? What does it matter where the vptr is placed? (And >>> of course, many objects have more than one vptr, and not all of >>> them can be at offset 0.) >> >> If you couldn't answer the question asked, you shouldn't have >> bothered posting! > > He did answer the question! He can speak for himself! |
Re: Is the vptr at the beginning of an object?
On Apr 2, 12:16 pm, "DaveB" <DBu...@usenet.net> wrote:
> James Kanze wrote: > > On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote: > >> In practice, across most compilers, is the vptr at offset 0 > >> of a class object? I've found some posts that say GCC puts > >> it at the end, but they were very old posts and I don't use > >> it now so can't test it. > > Who cares? What does it matter where the vptr is placed? > > (And of course, many objects have more than one vptr, and > > not all of them can be at offset 0.) > If you couldn't answer the question asked, you shouldn't have > bothered posting! I gave the only relevant answer. It doesn't matter where the compiler puts the vptr. It could put it anywhere, and change where it puts it from one version to the next, or even with a change in the compilation options. And of course, the question doesn't even make sense, since objects may have more than one vptr. -- James Kanze |
Re: Is the vptr at the beginning of an object?
On Apr 2, 8:25*am, Branimir Maksimovic <bm...@hotmail.com> wrote:
> On Fri, 2 Apr 2010 08:02:20 -0700 (PDT) > > > > James Kanze <james.ka...@gmail.com> wrote: > > On Apr 2, 12:16 pm, "DaveB" <DBu...@usenet.net> wrote: > > > James Kanze wrote: > > > > On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote: > > > >> In practice, across most compilers, is the vptr at offset 0 > > > >> of a class object? I've found some posts that say GCC puts > > > >> it at the end, but they were very old posts and I don't use > > > >> it now so can't test it. > > > > > Who cares? *What does it matter where the vptr is placed? > > > > (And of course, many objects have more than one vptr, and > > > > not all of them can be at offset 0.) > > > > If you couldn't answer the question asked, you shouldn't have > > > bothered posting! > > > I gave the only relevant answer. *It doesn't matter where the > > compiler puts the vptr. *It could put it anywhere, and change > > where it puts it from one version to the next, or even with a > > change in the compilation options. *And of course, the question > > doesn't even make sense, since objects may have more than one > > vptr. > > > -- > > James Kanze > > Is there possibility for implementation not to use vptr > at all? Eg implementation that would dispatch on 'if's' > based on type? Eg where indirect function calls are expensive? > I can imagine a vptr-less implementation, where each virtual function is implemented as a pointer within each object, rather than a vtbl implementation, where such pointers are a per-class thing. So to talk about the vptr at all is nonsense, especially since it isn't mandated. If you want to discuss vptr specifics, you'd almost by definition have to do it in a platform specific forum. And, as James has mentioned, in the case of MI and a vptr implementation, you'll probably have multiple vptrs. |
Re: Is the vptr at the beginning of an object?
"James Kanze" <james.kanze@gmail.com> wrote in message news:79618c05-f8f7-4c85-92f9-ede43dea8e6c@k17g2000yqb.googlegroups.com... > On Apr 2, 12:16 pm, "DaveB" <DBu...@usenet.net> wrote: >> James Kanze wrote: >> > On Apr 2, 9:56 am, "DaveB" <DBu...@usenet.net> wrote: >> >> In practice, across most compilers, is the vptr at offset 0 >> >> of a class object? I've found some posts that say GCC puts >> >> it at the end, but they were very old posts and I don't use >> >> it now so can't test it. > >> > Who cares? What does it matter where the vptr is placed? >> > (And of course, many objects have more than one vptr, and >> > not all of them can be at offset 0.) > >> If you couldn't answer the question asked, you shouldn't have >> bothered posting! > > I gave the only relevant answer. It doesn't matter where the > compiler puts the vptr. It could put it anywhere, and change > where it puts it from one version to the next, or even with a > change in the compilation options. And of course, the question > doesn't even make sense, since objects may have more than one > vptr. > Techno gibberish. I asked about common practice, not hypothetical theory, and it doesn't take anyone with one ioda of intuition to assume that I was talking about the simple case. Use of this forum to spout technobabble at any/every opportunity, is annoying at best. (If you can't help it because you are a nerd, then I apologize for not being cognitive of the affliction, and hope you get the help you need). |
| All times are GMT. The time now is 04:26 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.