On 22 Feb 2008 20:36:29 GMT,
(Richard Tobin)
wrote:
> In article <>,
> Keith Thompson <kst-> wrote:
>
> >Um, main *is* a function. Since it can be called recursively (whether
> >that's a good idea is a separate question), the compiler has to store
> >its automatically allocated local objects in some stack-like fashion
> >unless it can prove that main is never called recursively in the
> >program. But then, it can do the same kind of thing for any other
> >function; if the compiler (or linker?) can prove that two or more
> >calls to a function are active simultaneously, it can store that
> ^ never
> >function's local automatic objects in, say, the same place where
> >static objects are stored.
>
> In older versions of Fortran, recursion was not allowed, and it was
> common to allocate fixed locations for each non-parameter variable.
>
To be pedantic, I'd rather say not _supported_; it wasn't required to
work, and as you note often didn't, but the implementation wasn't
required to catch it, and usually didn't, especially if indirect.
It still isn't by default -- formally you have to specify RECURSIVE.
But on most if not all modern machines, the (performance) penalty for
using stack has been eliminated or even reversed, so compilers
often(?) use it even when not formally required. Although, at least
some Fortran compilers have options to put large and/or variably-sized
arrays in heap instead, allocated and deallocated at subprogram entry
and exit, because of (primarily) OSes that have stack size limits
small relative to that for the heap and also (importantly) the sizes
of data many Fortran programmers want to handle.
COBOL at least through 1985 also doesn't support recursion.
- formerly david.thompson1 || achar(64) || worldnet.att.net