PRB: Compiler Doesn't Lay Out Overloaded Functions in Order

Last reviewed: June 7, 1995
Article ID: Q131104
The information in this article applies to:
  • Microsoft OLE Libraries for Windows and Win32s, version 2.03
  • Microsoft OLE libraries included with:

        - Microsoft Windows NT version 3.5
        - Microsoft Windows 95
    
  • Microsoft Visual C++ for Windows, version 1.52
  • Microsoft Visual C++, 32-Bit Edition, version 2.1

SYMPTOMS

The Microsoft Visual C++ compiler does not lay out overloaded functions in the vtable in the order in which they are declared. This does not adhere to the COM binary standard. (See the OLE Specification section 3.1.1.1 for a discussion of the COM binary standard.) If there are no overloaded functions, the COM binary standard is followed.

In general, it is not a good idea to use overloaded methods in a COM interface because this precludes use of the interface from languages like C that do not support overloading.

CAUSE

All the overloads of a function are laid out together in successive entries in the reverse order of their declaration, overall in the order of the first overload of each name. Therefore given this declaration:

class A {

   virtual void a();
   virtual void b();
   virtual void a(int);
   virtual void b(int);
};

Entries in the vtable are laid out in this order: A::a(int), A::a(), A::b(int), A::b(). The COM binary standard requires that functions be laid out in the order in which they are declared.

STATUS

This behavior is built into the design. It cannot be modified because of legacy code that depends on this behavior.


Additional reference words: 2.03 1.52 4.00 3.50 2.10
KBCategory: kbprg kbole kbprb
KBSubcategory: LeTwoArc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 7, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.