Microsoft KB Archive/131104

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

Article ID: 131104

Article Last Modified on 12/3/2003

-

APPLIES TO

 Microsoft OLE 2.03 Microsoft OLE 4.0, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 95  Microsoft Visual C++ 1.52 Professional Edition, when used with:  Microsoft Windows NT 4.0</li></ul> </li> Microsoft Visual C++ 2.1</li></ul>

-

<div class="notice_section">

This article was previously published under Q131104

<div class="symptoms_section">

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.

<div class="cause_section">

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.

<div class="status_section">

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

Additional query words: 2.03 1.52 4.00 3.50 2.10

Keywords: kbprogramming kbprb KB131104

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.