myriachan | 1 Mar 2008 22:08
Picon

Incorrect vtable generation in MinGW?

I noticed that MinGW's G++ doesn't make vtables using the same algorithm as Visual C++, which can break COM
interfaces.  If there are two overloaded functions with the same name, Visual Studio will group the
functions of the same name together instead of preserve the ordering specified in the virtual table.

Input program:

struct Vtable
{
  virtual void Overloaded(int) = 0;
  virtual void Other() = 0;
  virtual void Overloaded(Vtable&) = 0;
};

void Function(Vtable& param)
{
  param.Overloaded(param);
}

Visual Studio assembly code (/Ox /Oy-):

	push	ebp
	mov	ebp, esp
	mov	ecx, DWORD PTR 8[ebp]
	mov	eax, DWORD PTR [ecx]
	mov	edx, DWORD PTR [eax]
	push	ecx
	call	edx
	pop	ebp
	ret

(Continue reading)

ATS | 1 Mar 2008 23:10
Picon

Re: Incorrect vtable generation in MinGW?

> I noticed that MinGW's G++ doesn't make vtables using the same algorithm as 
> Visual C++, which can break COM interfaces.  If there are two overloaded 
> functions with the same name, Visual Studio will group the functions of 
> the same name together instead of preserve the ordering specified in the 
> virtual table.

Both Visual C++ and G++ puts functions in order of declaration into the 
VTable. However, if the same name is used for several virtual functions,
there is a difference:

- G++ keeps to the order of declaration
- Visual C++ stores functions into the VTable in reversed order of 
declaration. 

Apparently the reason for VC++ to do this is backwards compatability 
with some pre-windows X86 std. COM had to support that. No better reason
than that. 

Stay away from virtual functions with the same name if you want cross
compiler operation. 

Regards
// ATS.

> 
> Input program:
> 
> struct Vtable
> {
>   virtual void Overloaded(int) = 0;
(Continue reading)

Ross Ridge | 2 Mar 2008 00:29
Picon
Picon
Favicon

Re: Incorrect vtable generation in MinGW?

myriachan writes:
>The real question is, which compiler is incorrect here according to COM?

Neither, it's your code that's incorrect.  Overloading methods isn't
supported by COM.  The MIDL compiler won't let you define an interface
with two methods that have same name.  It also won't let you define a
method that takes reference type as one of it's arguments.  You should
only use C types in your interface, otherwise you'll probably run into
other incompatibilites between Visual C++ and MinGW.

					Ross Ridge

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@...

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users


Gmane