[5810] in Athena Bugs
unfriendly behavior of f77
daemon@ATHENA.MIT.EDU (deckjf@ATHENA.MIT.EDU)
Fri Aug 24 00:47:43 1990
From: deckjf@ATHENA.MIT.EDU
To: bugs@ATHENA.MIT.EDU
Date: Fri, 24 Aug 90 00:46:53 EDT
I believe that f77 should have caught the following error. My program, in part,
was:
implicit undefined(a-z)
include 'define.cmn'
integer time, i1
.
.
.
i1 = time()
.
.
The included file defines common blocks that are used in many subroutines in my
program. One of the common blocks is:
common /time/ vara, varb, varc....
The call to time() was inserted into an already-working program because I wanted
to add CPU and elapsed time accounting to it. time() is a Fortran library
function; try "man 3f time" if you think I used it wrong!
What happened when I made this modification to my (already-working!) program was
that the call to time() resulted in an illegal instruction error, and the
program bombed. It took me a while to figure out why.
It appears that the compiler correctly compiled a subroutine call to global
symbol _time_, and the linker correctly resolved a reference to global symbol
_time_. But, naturally, the linker found my common block definition for _time_
before it found the library function.
I believe that this is an error in the compiler. It should have caught my
attempt to define the symbol time to be two different things.
You can prove this to yourself with the following simple program.
**** file: simple.f ****
implicit undefined(a-z)
C include 'cmn1.cmn'
integer time, i1
C real1 = 0.0
i1 = time()
write (*,*) i1
stop
end
----------
***** file: cmn1.cmn ****
real real1
common /time/ real1
-----------
% f77 simple.f
% a.out
If you compile, link and execute this program as shown, it works fine, and
prints a large integer on your terminal - exactly what it's supposed to do.
Remove the comments, and it produces an illegal instruction error. Set real1 =
3.14159, for instance, and it produces an illegal addressing mode error. There
must be values of real1 that are legal instructions, too!
(Further experimentation: this version compiles without an error, too....
implicit undefined(a-z)
real real1
integer time, i1
common/time/ real1
real1 = 3.14159
i1 = time()
write (*,*) i1
stop
end
)
I don't know what the Fortran standard says about this, but I think variable
names, named common names, and function/subroutine names have to be unique
within each program unit. Obviously, the source code had an error, and one that
the compiler should have been able to catch.