PRB: Using FORTRAN Input/Output Statements with Basic

Article translations Article translations
Article ID: 62215 - View products that this article applies to.
This article was previously published under Q62215
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page


If a compiled Basic program is linked with a large or huge memory model FORTRAN routine that uses either CHARACTER data or the FORTRAN READ or WRITE statements, the Basic program will not be able to access the far heap.


To avoid this problem, link only to FORTRAN routines compiled in the medium memory model.

FORTRAN routines placed in a Quick library will work correctly, even if the FORTRAN is compiled in the large or huge memory model.


A number of symptoms can indicate the problem above. Here are two:

  1. Basic function FRE(-1), which should return the total available memory (far heap + data segment), returns the same amount of space as the available data segment space. The amount of available data segment space can also be obtained by FRE(0), and if Basic cannot access the far heap due to the above problem, the amount returned by these two functions will be equal.
  2. Basic will report "Out of memory" when trying to dimension a $DYNAMIC array larger than the remaining space in the data segment. Since Basic cannot access the far heap, the free portion of the data segment is the only available memory, and memory will be exhausted if the array is larger than the space remaining in the data segment.
Below are two FORTRAN examples that demonstrate the problem. Program 1 shows a FORTRAN call without I/O statements. Program 2 shows the same program with one WRITE statement included.

NOTE: The Basic program does not even have to call the FORTRAN subprogram; it is the allocation of the FORTRAN data space that causes the error.

To compile the FORTRAN.OBJ, use the following commands:
   FL /C /FPi /AL FORPROG1.FOR;    'for subprogram #1
   FL /C /FPi /AL FORPROG2.FOR;    'for subprogram #2
To compile the Basic.OBJ, use the following command:
Then, link the files together as follows:
   LINK /NOE BASPROG+FORPROG1,PROG1;   'for program #1
   LINK /NOE BASPROG+FORPROG2,PROG2;   'for program #2
To run the programs, type either PROG1 or PROG2.

Code Samples

   DECLARE SUB ForSub ()
   DIM heap%(2048)
   COMMON /nmalloc/ heap%()
   PRINT "In Basic...memory = "; FRE(-1)
   CALL ForSub
   PRINT "Back in Basic.  memory = "; FRE(-1)

FORTRAN Program 1

         subroutine forsub

FORTRAN Program 2

         subroutine forsub
         WRITE(*,*)'This is the FORTRAN program.'


Program 1

In Basic...memory = 416968
Back in Basic. memory = 416968

Program 2

In Basic...memory = 53992
Back in Basic memory = 53992


If the above example is used, but the FORTRAN compiler is instructed to use the medium memory model (/AM instead of /AL) and the library MLIBFORE is linked instead of LLIBFORE, the program will work correctly.


Article ID: 62215 - Last Review: August 23, 2013 - Revision: 2.1
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Professional Development System 7.0
kbnosurvey kbarchive kbprb KB62215

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from