Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Subroutine bug with 4.2 BSD F77.

2 views
Skip to first unread message

B. Banerjee

unread,
Jun 13, 1986, 11:29:14 AM6/13/86
to
Description:

User defined functions always return a value of 0 (including
logical functions).

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.

Doug Gwyn

unread,
Jun 15, 1986, 12:25:34 AM6/15/86
to
> print *, bug(i)

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.

Comfy chair

unread,
Jun 16, 1986, 11:20:14 AM6/16/86
to
>Description:
>
> User defined functions always return a value of 0 (including
> logical functions).

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!

B. Banerjee

unread,
Jun 16, 1986, 12:39:12 PM6/16/86
to

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

s...@mips.uucp

unread,
Jun 16, 1986, 2:36:07 PM6/16/86
to
> User defined functions always return a value of 0 (including
> logical functions).
>
> integer i
> i = 1
> print *, bug(i)
> stop
> end
>
> integer function bug(i)
> integer i
> bug = 2
> return
> end

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

Glenn A. Zazulia

unread,
Jun 16, 1986, 4:04:33 PM6/16/86
to

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

Jim Thompson

unread,
Jun 18, 1986, 7:18:57 AM6/18/86
to

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 .]


Jim Thompson

unread,
Jun 18, 1986, 7:31:20 AM6/18/86
to
In article <31...@sjuvax.UUCP> bban...@sjuvax.UUCP writes:
>Description:
>
> User defined functions always return a value of 0 (including
> logical functions).
>
>Repeat-By:
>
> Compile and execute the following program.
>============================================================
> integer i
C>>>>>>>>>>>>>>>>>>insert this:
integer bug
C>>>>>>>>>>>>>>>>>>end of fix.
> i = 1
k>

>Fix:
> Hopefully fixed in 4.3 BSD.

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'.

Jim Thompson

unread,
Jun 18, 1986, 7:35:45 AM6/18/86
to
In article <31...@sjuvax.UUCP> bban...@sjuvax.UUCP writes:


insert ',bug' in line one.

Andrew Koenig

unread,
Jun 18, 1986, 9:51:11 AM6/18/86
to
> 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

> 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.

Walter M. Lioen

unread,
Jun 23, 1986, 1:34:04 PM6/23/86
to rnews@mcvax
In article <31...@sjuvax.UUCP> bban...@sjuvax.UUCP writes:

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

kau...@shasta.uucp

unread,
Jun 25, 1986, 1:06:15 PM6/25/86
to

There are old days and *OLD* days. It would have worked just fine
with Fortran IV (previously called FORTRAN IV) on the IBM 7090!

0 new messages