BUG: Trying to Export Static Function Causes L1101

ID: Q114587

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

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

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

SYMPTOMS

When compiling a Windows program that contains a function header and prototype which are mismatched and alternately contain the "static" and "__export" keywords, the fast compiler will return:

  TEST.OBJ(c:\testdir\test.c) : fatal error L1101: invalid object
  module
  Object file offset: ### Record type: 90


RESOLUTION

If ExampleWindowProc() is prototyped as

   LRESULT CALLBACK __export ExampleWindowProc (WINDOWS_PARAMS)

and if ExampleWindowProc() is declared as:

   static LRESULT CALLBACK ExampleWindowProc (WINDOWS_PARAMS)

error L1101 will result because the compiler generates incorrect code. The error will also occur if the function declaration and prototype are reversed.

Static functions cannot be exported, so the code described above would be incorrect, but the compiler does not issue the correct error message. If the function does not need to be static, then remove the "static" keyword and the code will compile and link correctly. If the function does not need to be exported, then remove the "__export" keyword and the code will compile and link cleanly.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft C/C++ compiler for MS-DOS versions 7.0, 8.0 and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The compiler should generate the following error:

   "C2201: cannot export static declarations"

Static functions have internal linkage and therefore (by definition) cannot be exported. The code is also incorrect because the prototype does not match the function header. The compiler does generate a C2201 error if the "__export" keyword is in the same prototype/function header as the "static" keyword.

NOTE: If the MakeProcInstance line is deleted in the code example below, the compiler will not generate the code which causes the linker to fail.

Sample Code

The following sample code reproduces the problem:

//  Sample.cpp

/* Compile options needed:
   cl /f /GA /G2 /c sample.cpp, will reproduce the L1101 error.
   The /f switch invokes the fast compiler.
   Note that if building an application with the /Od compiler
   switch, the fast compiler will be implicitly invoked.

   cl /f /O1 /GA /G2 /c sample.cpp, will not produce the L1101 error.
*/ 

#include <windows.h>

FAR PASCAL MyProc( /*paramters*/ ); __export FAR PASCAL ConfDlg( /*paramters*/ );

static FAR PASCAL ConfDlg( /*paramters*/ ) {

    return (0);
}

FAR PASCAL MyProc(/*parmaters*/) {

    DLGPROC lpProcDialog;
    HANDLE hInst;
    lpProcDialog = MakeProcInstance((DLGPROC) ConfDlg, hInst);
    return NULL;
}

Additional reference words: 1.00 1.50 7.00 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CLIss Keywords : kb16bitonly

Last Reviewed: July 23, 1997