PRB: Mixed Language Apps Will Not Run Due to Extra END

Last reviewed: July 17, 1995
Article ID: Q86452
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 5.0 and 5.1
  • Microsoft FORTRAN for OS/2, versions 5.0 and 5.1

SYMPTOMS

Mixed-language C and FORTRAN Windows applications may appear to fail to start when executed or, under CodeView for Windows, may immediately exit with the Program Terminated Normally message on the first step into the application.

CAUSE

The FORTRAN code may have an additional END statement following the subroutine or function declaration. An additional END statement is interpreted by the compiler as an empty main program declaration, and thus causes the insertion of the entry point _main.

The startup code in a Windows 3.x executable looks first for a function named main (_main with C declaration style); if it cannot find the main (or _main) function, it looks for a function called WinMain(). If neither of these functions exist, the following run-time error is generated:

   R6021: No Main Function

Because the FORTRAN code declared a _main function that does nothing, the main window of the program is not created and the application exits immediately after it starts. This problem is more common with mixed-language C and FORTRAN Windows applications.

RESOLUTION

Check all FORTRAN code for extra END statements and remove them.

STATUS

This functionality is by design. Windows applications should have only WinMain() functions as entry points. The problem is caused by the interpretation that standard FORTRAN syntax gives to an extra END statement.

MORE INFORMATION

With non-Windows applications, an extra END statement causes the linker to generate the following error:

   error L2025: _main : symbol defined more than once

Windows applications do not have an _main function, however, so no linker error is generated.

To duplicate this problem, use the MULMIX project example that comes with FORTRAN 5.1 and add an additional END statement below the MUL subroutine in the MULF.FOR file. For more information, query on the following words in the Microsoft Knowledge Base:

   winmain main qwin100


Additional reference words: 5.10
KBCategory: kbprg kbinterop kbprb
KBSubCategory: FORTLngIss


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