PRB: C2080 Error When Callback Function Declared as _fastcall

Last reviewed: July 17, 1997
Article ID: Q77141
6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                 | WINDOWS
kbtool kbprb

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, versions 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

An attempt to compile an application fails and one of the following messages appears on the screen. For Microsoft C/C++ versions 7.0 and 8.0:

   error C2080 : illegal __far __fastcall function or __saveregs
   function

For Microsoft C versions 6.0, 6.0a, and 6.0ax:

   error C2080: illegal far _fastcall function

CAUSE

An application for the Microsoft Windows operating system declares a FAR function with the __fastcall calling convention and the compiler command line contains the /Gw or /GEf (and /GA or /GD) compiler option switch.

Microsoft Windows callback functions do not support the _fastcall calling convention. Because the /Gw or /GEf (combined with /GA or /GD) compiler option switches generate the Windows prolog and epilog code for all __far functions, the compiler generates the errors listed above for each __fastcall funciton.

RESOLUTION

Modify the source code to remove the __fastcall declaration from callback functions. An application can use the __fastcall calling convention for its internal functions; in other words, those functions called within the program and not by Windows itself.

MORE INFORMATION

In an application designed for the Microsoft Windows operating system, callback functions include window procedures, hook funcitons, enumeration functions, and so forth.

The Windows prolog code modifies the AX register. However, in the __fastcall calling convention, the AX register contains one funciton parameter. The errors are caused by this conflicting register use.

When an application specifies both the __export and __fastcall options, the compiler generates the following message:

   error C2216:  __fastcall cannot be used with __export


Additional reference words: 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00 8.00c
KBCategory: kbtool kbprb
KBSubcategory: CLIss
Keywords : kb16bitonly


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: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.