[comp.lang.fortran] Dynamic Memory Management in Fortran

mlzerkle@athena.mit.edu (Michael L Zerkle) (11/16/90)

I would like the thank everyone for there comments and advice RE: my 
previous posting.  I now see what I was doing wrong.  

Fortran sets the address of arrays at compile-time, and will not permit
the address to be changed.  As a result, the Fortran definition,

      real*8 a(1)

translates to C something like,

      const double *a;

I thought that since most if not all Fortran compilers are written in C
that I might be able to fool the compiler into doing what I wanted.  
That is just not the case.

What I ended up doing was writing some C functions that implemented the BSD
Fortran bindings to the falloc() and free() subroutines.  Therefore, on the
systems that have the falloc() and free() subroutine is use the resident 
version, and on the systems that do not (the ones running Sys 5.3, etc) I
use my bindings.

Everyone, thanks again for your help!

Mike Zerkle
mlzerkle@athena.mit.edu

john@ghostwheel.unm.edu (John Prentice) (11/16/90)

This subject has been pretty well hashed out, but I wanted to add one thing
that I didn't see mentioned.  Some compilers (notably the Sun and Cray 
Fortran compilers) have implemented pointers and also have Fortran callable
links to malloc to allocate a block of memory and return the pointer
address.  For such compilers, dynamic memory allocation is truly trivial.

John Prentice
john@unmfys.unm.edu