BUG: Initialization Problem with FORTRAN and BasicLast reviewed: February 6, 1997Article ID: Q79825 |
The information in this article applies to:
SYMPTOMSMixed-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.
CAUSEBasic 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.
RESOLUTIONThe 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.
STATUSMicrosoft 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 INFORMATIONThe 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 CodeDIM 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) endNote: 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/2all: test.exe ftest.obj : ftest.for fl /c /Zi /Od ftest.forbtest.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-DOSall: test.exe ftest.obj : ftest.for fl /c /Zi /Od ftest.forbtest.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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |