From: | dlmoore@ix.netcom.com (David L Moore) |
Newsgroups: | comp.compilers |
Date: | 30 Jun 1996 16:52:25 -0400 |
Organization: | Netcom |
References: | 96-05-061 96-05-163 96-06-048 96-06-081 |
Keywords: | Fortran, comment |
> f2c is a good case study for illustrating one type of problem with language A
> to language B translation systems.
>
> [f2c makes local variables static]
>
This used to be a common misconception - that locals in Fortran were
static and therefore retained their values from one call of a
procedure to the next. This was how Fortran was implemented on
some early machines.
Fortran 77 introduced the "save" statement to allow the programmer
to specify which variables should be static. Other variables can
be static or dynamic at the choice of the compiler.
So, either f2c has never been updated to the 77 standard in this area,
or else this is an example of a premature "optimisation" by a tool. In
either case, it is the tool that should be fixed, not the C optimizer.
[Sigh. Two minutes spent looking at the f2c manual page reveals that it has
an option to make variables automatic when it can. Some years ago I wrote
one of the earlier F77 compilers, INfort, and since it was running on a
PDP-11 with only a 16 bit address space, I tried hard to put everything on
the stack that I could. The customers hated it. There's millions of lines
of legacy Fortran code, almost all of which assumes that all variables are
static, regardless of what the F77 standard says. So I had to do the same
thing as f77 and f2c (which is f77 with a C generating back end) do, make
everything static unless requested otherwise. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.