A potential bug since the earliest days of Fortran is passing a
constant to a subroutine, and then changing the value of the dummy
argument.
In at least some Fortran system, this modifies the value of a constant
used other places in a program.
As this was known when PL/I was designed, it is defined such that
modifiable constants are passed to called procedures. C avoids it by
not allowing the & operator on constants. (Though K&R allows
modification of string constants.)
Somehow, in all the years, that feature was never added to Fortran.
It is easy to write programs and test for it, but I wonder if there
are any stories for real program that had this bug, and even better,
stories about the difficulty of finding it, or problems caused by it.
gah4 <gah4@u.washington.edu> schrieb:
A potential bug since the earliest days of Fortran is passing a
constant to a subroutine, and then changing the value of the dummy
argument.
I actually got bitten by that while using a mainframe for scientific
work as a student. It's been a few decades, so I don't recall too
many details. It was difficult to find, but I was paid by the hour,
so I didn't mind too much :-)
Algol 60 tried to define
its argument passing in an elegant way, and accidentally invented call
by name when they meant call by reference. -John]
A[1] := 10
[The constant stomping issue far predates S/360. As soon as Fortran II
added subroutines on the 704, there were constant arguments you could
change by mistake. The problem is that it took quite a while for people
to sort out the differences among call by reference, call by value,
and call by copy in/out. Fortran on the 70x and S/360 user reference
for array arguments, copy in/out for scalars.
I just have the IBM System/360 Operating System FORTRAN IV (H)
Programmer's Guide, Fourth Edition, open (isn't Bitsavers great?).
It states, on page 108
Argument List
The argument list contains addresses of
variables, arrays, and subprogram names
used as arguments. Each entry in the argu-
ment list is four bytes and is aligned on a
full-word boundary. The last three bytes
of each entry contain the 24-bit address of
an argument. The first byte of each entry
contains zeros, unless it is the last entry
in the argument list. If this is the last
entry, the sign bit in the entry is set on.
So, apparently no copy in/out on that particular compiler, at least.
It also shows the (ab)use that was possible of the uppermost byte,
because clearly 24 bits are enough for everybody and for all
time, right? :-)
A potential bug since the earliest days of Fortran is passing a
constant to a subroutine, and then changing the value of the dummy
argument.
In at least some Fortran system, this modifies the value of a constant
used other places in a program.
As this was known when PL/I was designed, it is defined such that
modifiable constants are passed to called procedures. C avoids it by
not allowing the & operator on constants. (Though K&R allows
modification of string constants.)
Somehow, in all the years, that feature was never added to Fortran.
It is easy to write programs and test for it, but I wonder if there
are any stories for real program that had this bug, and even better,
stories about the difficulty of finding it, or problems caused by it.
1 ok1 1 + .
2 ok
ok1 .
2 ok1 1 + .
4 ok
[The 70x series had 15 bit word addressing with index registers. Even
though they mostly did sign/magnitude arithmetic, indexing worked by
doing a two's complement subtract of the index register from the
address in the instruction. (I've seen lots of guesses why they did
that, but never found an actual source.) So Fortran arrays were stored
in reverse order starting in high memory. 70x Fortran did not have
the /X/ argument specifier and I cannot find anything in the manuals
about argument aliasing, although the calling sequence example in the
FAP assember program shows how to copy in arguments.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 20:55:04 |
| Calls: | 810 |
| Calls today: | 1 |
| Files: | 1,287 |
| D/L today: |
11 files (21,026K bytes) |
| Messages: | 194,568 |