← Back to context

Comment by SulphurCrested

3 days ago

DEC VAX/VMS Fortran 77, ca. mid-1980s, did use the process stack for call, return and arguments; all the compilers DEC supplied on that platform did, because there was a common calling sequence among all the languages and you could call any language from any other.

I dimly remember the reason for it not being recursive by default was it didn’t put local variables on the stack, and I guess /RECURSIVE (which I don’t remember) controlled that. Probably there was some SYSGEN parameter which limited stack size. There were people who would declare giant arrays as locals rather than putting them in named COMMON, so the user-friendly compiler default was to put them in a fixed PSECT because those same people would never be using recursion.

To this day some Fortran compilers put large local variables into static storage rather than the stack. Because many old Fortran programs were written with the assumption that all procedure variables were statically allocated, and thus having huge arrays as local variables wasn't an issue.

This kind of code then easily breaks by overflowing the stack if the compiler allocates them there.

But this then doesn't work that well if the procedure is called recursively, or concurrently from multiple threads.

Making this even worse, in a recent Fortran standard (2008?) this was reversed such that procedures must be explicitly marked with NON_RECURSIVE in order to allow the compiler to allocate variables statically. Undoubtedly the right decision given the increasing prevalence of threads as well as recursive algorithms, but a gotcha for compiling old dusty deck code.