[net.bugs.4bsd] Subroutine bug with 4.2 BSD F77.

bbanerje@sjuvax.UUCP (B. Banerjee) (06/13/86)

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.

gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/15/86)

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

ken@rochester.ARPA (Comfy chair) (06/16/86)

>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: ken@rochester.arpa
Snail: CS Dept., U. of Roch., NY 14627. Voice: Ken!

bbanerje@sjuvax.UUCP (B. Banerjee) (06/16/86)

In article <3174@sjuvax.UUCP> I wrote:
>> 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.

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
				bbanerje@sju.edu

sjc@mips.UUCP (06/16/86)

> 	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@emory.UUCP (Glenn A. Zazulia) (06/16/86)

In article <3174@sjuvax.UUCP> version B 2.10.2 9/18/84; site emory.UUCP version B 2.10.2 9/5/84; site sjuvax.UUCP emory!akgua!akguc!mtune!mtuxo!houxm!mhuxt!mhuxr!ulysses!allegra!princeton!astrovax!sjuvax!bbanerje bbanerje@sjuvax.UUCP (B. Banerjee) writes:
>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.

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

anderson@nbs-amrf.UUCP (Bill Anderson) (06/17/86)

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

You need to specify the type for bug (i.e. integer bug).

Bill Anderson, NBS

...!seismo!nbs-amrf!anderson

jim@otto.UUCP (Jim Thompson) (06/18/86)

In article <3174@sjuvax.UUCP> bbanerje@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
>	i = 1
>	print *, bug(i)
>	stop
>	end
>
>
>	integer function bug(i)
>	integer i
>
>	bug = 2
>	return
>	end
>
>Fix:
>	Hopefully fixed in 4.3 BSD.

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@otto.UUCP (Jim Thompson) (06/18/86)

In article <3174@sjuvax.UUCP> bbanerje@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

{ihnp4,sdcrdcf}!otto!jim

[ Usual disclamer:  I have no opinion, therefore I don't exist .]

	

jim@otto.UUCP (Jim Thompson) (06/18/86)

In article <3174@sjuvax.UUCP> bbanerje@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
>	i = 1
>	print *, bug(i)
>	stop
>	end
>
>
>	integer function bug(i)
>	integer i
>
>	bug = 2
>	return
>	end
>
>Fix:
>	Hopefully fixed in 4.3 BSD.


insert ',bug' in line one.
-- 


					Jim Thompson

{ihnp4,sdcrdcf}!otto!jim

[ Usual disclamer:  I have no opinion, therefore I don't exist .]

	

ark@alice.UucP (Andrew Koenig) (06/18/86)

> 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@zuring.uucp (Walter M. Lioen) (06/23/86)

In article <3174@sjuvax.UUCP> bbanerje@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
>	i = 1
>	print *, bug(i)
>	stop
>	end
>
>
>	integer function bug(i)
>	integer i
>
>	bug = 2
>	return
>	end
>
>Fix:
>	Hopefully fixed in 4.3 BSD.

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: walter@mcvax.uucp
ARPA: walter%mcvax.uucp@seismo.css.gov

kaufman@Shasta.UUCP (06/25/86)

In article <5657@alice.uUCp> ark@alice.UucP (Andrew Koenig) writes:
>> 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.

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