Repeat-By:
Compile and execute the following program.
============================================================
integer i
i = 1
print *, bug(i)
stop
end
integer function bug(i)
integer i
bug = 2
return
end
Fix:
Hopefully fixed in 4.3 BSD.
At this point, bug() is assumed to be a real-valued function.
> integer function bug(i)
But now you define it incompatibly.
Too bad the compiler doesn't report an error for this.
Fix:
integer i
+ integer bug
i = 1
print *, bug(i)
stop
end
integer function bug(i)
integer i
bug = 2
return
end
>Fix:
> Hopefully fixed in 4.3 BSD.
Meta-fix:
Read the Fortran standard.
Ken
--
UUCP: ..!{allegra,decvax,seismo}!rochester!ken ARPA: k...@rochester.arpa
Snail: CS Dept., U. of Roch., NY 14627. Voice: Ken!
I'm sorry people. As has been pointed out to me by various people,
one needs a forward declaration of bug in order to over-ride the
default typing of Fortran.
This was brought to my attention by a local user. My previous
experience with Fortran has been with Fortran IV in the old days
of punched cards. Both the compilers I used previously would have
accepted the above without problem. I guess that they just used
extensions.
My apologies to anyone inconvenienced by the above posting.
Regards,
Binayak Banerjee
{allegra | astrovax | bpa | burdvax}!sjuvax!bbanerje
bban...@sju.edu
Because "bug" begins with the letter "b", the main program thinks that
its type is "real", despite the later definition of it as "integer".
Change "integer i" to "integer i, bug" in the main program and your
program will work. (This is ANSI X3.9-1978 Fortran, not a bug: when the
compiler processes program unit "x", it is not allowed to use any
knowledge it may have about program unit "y", even if "x" and "y"
appear in the same file--even if "y" precedes "x" in the file.)
--
...decwrl!mips!sjc Steve Correll
There is no bug here! You forgot to declare your function 'bug' to be
of type integer in MAIN. Without the declaration, the function 'bug'
will pass back an integer value, but be interpreted as real in MAIN
(implicitly typed as such). Remember that the default type of a function,
like all variables, whose name begins with any letter other than 'i' - 'n'
is real, unless otherwise declared.
--
Glenn Zazulia
Emory University | {akgua,sb1,gatech,decvax}!emory!glenn USENET
Dept of Math and CS | glenn@emory CSNET
Atlanta, Ga 30322 | glenn.emory@csnet-relay ARPANET
Add this little bit and it runs just fine, thank you. :-)
integer i,bug
(prints '2')
Now, is this a bug or a feature?
The same 'bug' exists in VMS fortran.
(And the same fix applies.)
--
Jim Thompson
{ihnp4,sdcrdcf}!otto!jim
[ Usual disclamer: I have no opinion, therefore I don't exist .]
Now the only remaining question is:
Is this really a bug?
Note: VMS fortran does the same thing. Namely,
if bug is declaired then the proper result ('2') is printed.
If not, both output a '0'.
insert ',bug' in line one.
> This was brought to my attention by a local user. My previous
> experience with Fortran has been with Fortran IV in the old days
> of punched cards. Both the compilers I used previously would have
> used extensions.
I'll bet bet it wouldn't have worked in "the old days,"
at least not on IBM systems. IBM mainframes have separate
integer and floating-point registers. There's just no
way that the compiler could do the right thing without
the declaration.
Fix: %s/bug/nobug/g
--
Mail: Walter M. Lioen, CWI, P.O. Box 4079, 1009 AB Amsterdam, The Netherlands.
UUCP: {seismo,decvax,philabs,okstate,garfield}!mcvax!walter
or: wal...@mcvax.uucp
ARPA: walter%mcvax...@seismo.css.gov
There are old days and *OLD* days. It would have worked just fine
with Fortran IV (previously called FORTRAN IV) on the IBM 7090!