469,602 Members | 1,619 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

__vfptr problem in VC++.NET

Hi All,

I am porting an application from watcom to vc compiler. In watcom and
other compiler (other then vc) memory allocation of __vfptr inside
class object are different. In vc __vfptr is allocated top of the class
object i.e base address of class objects are same as __vfptr address.
But in watcom compiler __vfptr is allocated end of the class object.
Due to this difference, I am getting problem in accessing the member
variable address correctly. Is there any way in vc compiler option to
bring __vfptr from top to bottom of the class object.

Let's take a class example

Class exp_v
{
virtual void foo(void) {};
private:
int a;
int b;
};
In Watcom:-

|-----------------|<-- 0x3660(BaseAddress)
|int a |
|-----------------|<-- 0x3664
|int b |
|-----------------|<-- 0x3668
|__vfptr |
|-----------------|
In VC++.NET:-

|-----------------|<-- 0x3660(BaseAddress)
|__vfptr |
|-----------------|<-- 0x3664
|int a |
|-----------------|<-- 0x3668
|int b |
|-----------------|
Thanks & Regards
Debadeepti Sahu.

Jul 23 '05 #1
3 4379
BTW this is about VC++7, not .NET, which is a different (slobberin') animal.

debadeepti wrote:
I am porting an application from watcom to vc compiler. In watcom and
other compiler (other then vc) memory allocation of __vfptr inside
class object are different. In vc __vfptr is allocated top of the class
object i.e base address of class objects are same as __vfptr address.
But in watcom compiler __vfptr is allocated end of the class object.
Due to this difference, I am getting problem in accessing the member
variable address correctly. Is there any way in vc compiler option to
bring __vfptr from top to bottom of the class object.
What does "accessing the member variable address" mean? You neglected to
post code to illustrate that.
Class exp_v
{
virtual void foo(void) {};
private:
int a;
int b;
};


If you use the "pointer to member" language feature - which is really a
"smart offset", you shouldn't have trouble. And if you use the 'offsetof()'
macro, you shouldn't either.

But if you somehow stored the byte offset of a member into a data file, and
then need to use that offset after the Replace Compiler Refactor, you will
need to simply encapsulate your discovery of the size and location of the
__vfptr, if any, and live with extra math in your access code, right?

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #2
<de********@indiatimes.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com
Hi All,

I am porting an application from watcom to vc compiler. In watcom and
other compiler (other then vc) memory allocation of __vfptr inside
class object are different. In vc __vfptr is allocated top of the
class object i.e base address of class objects are same as __vfptr
address. But in watcom compiler __vfptr is allocated end of the class
object. Due to this difference, I am getting problem in accessing the
member variable address correctly. Is there any way in vc compiler
option to bring __vfptr from top to bottom of the class object.

Let's take a class example

Class exp_v
{
virtual void foo(void) {};
private:
int a;
int b;
};
In Watcom:-
-----------------|<-- 0x3660(BaseAddress)
int a |
-----------------|<-- 0x3664
int b |
-----------------|<-- 0x3668
__vfptr |
-----------------|

In VC++.NET:-
-----------------|<-- 0x3660(BaseAddress)
__vfptr |
-----------------|<-- 0x3664
int a |
-----------------|<-- 0x3668
int b |
-----------------|


I believe that the answer to your question is no: you cannot change where
the __vfptr is located. However, the best place to ask is

public.microsoft.vc.language

This is an implementation detail that a programmer normally doesn't need to
know anything about. Writing code that depends on implementation details is
asking for exactly the sort of trouble you are now having. What are you
doing that requires this information?

--
John Carson
Jul 23 '05 #3
de********@indiatimes.com wrote:
Hi All,

I am porting an application from watcom to vc compiler. In watcom and
other compiler (other then vc) memory allocation of __vfptr inside
class object are different. In vc __vfptr is allocated top of the class
object i.e base address of class objects are same as __vfptr address.
But in watcom compiler __vfptr is allocated end of the class object.
Due to this difference, I am getting problem in accessing the member
variable address correctly. Is there any way in vc compiler option to
bring __vfptr from top to bottom of the class object.


I don't think this is possible. But actually, I don't see why you should
ever care where the vtable pointer is. What exactly are you having problems
with?

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Tatu Portin | last post: by
4 posts views Thread by Anthony Gallagher | last post: by
2 posts views Thread by vemulakiran | last post: by
15 posts views Thread by Michael Tissington | last post: by
7 posts views Thread by Norman Diamond | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.