FIX: Member Conversion Function Calling Convention Incorrect (102619)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
This article was previously published under Q102619 SYMPTOMS
After compiling an application with Microsoft C/C++ for MS-DOS, an
attempt to link the application fails and Microsoft LINK generates the
following message:
error L2029: 'public: __near __pascal CMyclass::operator`int
const __near*' (void)const __near' : unresolved external
After compiling an application with Microsoft C/C++ 32-bit Edition, an
attempt to link the application fails and Microsoft LINK generates the
following messages:
warning LNK4016: unresolved external symbol "??BCMyclass@@QBGPBHXZ
(public: __stdcall CMyclass::operator`int const *' (void)const )"
error LNK1120: 1 unresolved externals
CAUSE
Microsoft C/C++ compiler version 8.0 and 8.0c for MS-DOS and Windows
always uses the __cdecl calling convention for functions declared as
follows:
<classname>::operator const <type-specifier> *() const
However, if the compiler command line includes the /Gc compiler option
switch, the function has the __pascal calling convention. Normally,
every member function of a class uses the __pascal calling convention
without regard to the presence of the /Gc compiler option switch.
For example, if you build an application with the Microsoft Foundation
Class Library and refer to the function CString::operator const char
*() const, an L2029 error occurs if you specify the /Gc compiler
option switch. Because the Class Library was built without the /Gc
option, the conversion function in the library has the __cdecl calling
convention. If you build your application with the /Gc option switch,
it attempts to call the conversion function with the __pascal calling
convention.
A similar problem occurs in Microsoft C/C++ 32-bit Edition if you
specify the /Gz compiler option switch. Normally, each class member
function uses the thiscall calling convention without regard to the
presence of the /Gz compiler option switch. However, if the compiler
command line specifies the /Gz compiler option switch, the conversion
function uses the __stdcall calling convention.
RESOLUTION
In Microsoft C/C++ version 8.0 for MS-DOS and Windows, modify the
compiler command line to remove the /Gc compiler option switch. Doing
so compiles the conversion function with the __cdecl calling
convention. In Microsoft C/C++ version 8.0 (32-bit), modify the
compiler command line to remove the /Gz compiler option switch. Doing
so compiles the conversion function with the thiscall calling
convention.
STATUS
Microsoft has confirmed this to be a bug in the products listed at the
beginning of this article. This bug was corrected in Visual C++ version
2.0.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbbug kbCompiler kbCPPonly kbfix KB102619 |
---|
|