BUG: Initialization Problem with FORTRAN and Basic

ID: Q79825

5.00 5.10 | 5.00 5.10

MS-DOS    | OS/2
 kbinterop

The information in this article applies to:

SYMPTOMS

Mixed-language programs with Microsoft FORTRAN 5.0 or 5.1 and Microsoft Basic 7.1, in which the FORTRAN code opens a file or accesses the near heap, can stop the machine upon execution. This problem occurs while running the program under both MS-DOS and OS/2.

CAUSE

Basic calls its heap initialization sequence twice and FORTRAN calls its initialization sequence once. The second time Basic calls its initialization sequence, it overwrites the information that FORTRAN requires to do file I/O.

RESOLUTION

The Basic program must explicitly call the FORTRAN initialization routine before calling any other FORTRAN routine that does file I/O. It should be called only once, typically at the start of the Basic main program. This routine will rewrite the required FORTRAN file structure information and allow FORTRAN file I/O to function correctly.

STATUS

Microsoft has confirmed this to be a problem in Microsoft FORTRAN version 5.0 and 5.1 for MS-DOS and OS/2. We are researching this problem and will post new information here as it becomes available.

MORE INFORMATION

The FORTRAN initialization routine that needs to be called is named __FFinit. The easiest way to call this routine is to use a DECLARE statement in Basic that uses the ALIAS keyword. The following sample code illustrates this solution and runs as expected. If the Basic call to __FFinit is commented out, the program will stop the machine under MS-DOS and stop the current process under OS/2.

Basic Sample Code

DIM HEAP%(2048) COMMON SHARED /NMALLOC/ HEAP%()

DECLARE SUB FINIT CDECL ALIAS "__FFinit" DECLARE SUB FORTSUB

CALL FINIT CALL FORTSUB

END

FORTRAN Sample Code

      subroutine fortsub

      open(1,file='test.dat')
      write(1,*) 'Writing to file in FORTRAN'
      print*, 'Finished writing to file in FORTRAN'
      close(1)
      end

Note: The following MAKE files are only for use with FORTRAN 5.1. To use FORTRAN 5.O, you must specify a C-compatible FORTRAN library and also a C 6.0 run-time library on the link line. For additional information, please see the following article in the Microsoft Knowledge Baes:

   ARTICLE-ID: Q66428
   TITLE     : How to Link Basic 7.1 with C 5.1, FORTRAN 5.0, and Pascal
               4.0

MAKE File for OS/2

all: test.exe

ftest.obj : ftest.for

  fl /c /Zi /Od ftest.for

btest.obj : btest.bas
  bc /o /Fs /Zi /LP btest.bas;

test.exe : btest.obj ftest.obj
  link /NOD /NOE /CO btest ftest,test.exe,nul,bcl71efp llibfep os2;

MAKE File for MS-DOS

all: test.exe

ftest.obj : ftest.for

  fl /c /Zi /Od ftest.for

btest.obj : btest.bas
  bc /o /Fs /Zi /LR btest.bas;

test.exe : btest.obj ftest.obj
  link /NOD /NOE /CO btest ftest,test.exe,nul,bcl71efr llibfer;

Additional reference words: 5.10 5.00 7.10 F6200
KBCategory:    kbinterop
KBSubcategory: FORTLngIss
Keywords          : kbcode kbFortranPS kbLangFortran 
Version           : 5.00 5.10 | 5.00 5.10
Platform          : MS-DOS OS/2

Last Reviewed: May 23, 1998