[comp.lang.fortran] Is this valid fortran

mikem+@andrew.cmu.edu (Michael Meyer) (10/03/89)

Hi:
Could someone please tell me if the following function is valid fortran?
 The code does compile (but produced execution errors) on the Decstation
3100.  
	complex function fred(x,y)
	complex x,y
	fred=(10,10)
	fred= x*conjg(y) + fred
	return
	end

My question is whether it is allowable to treat the function name (fred)
as a variable in the body of the function.  Is is allowable to update
the value of fred?  I notice in similar LINPACK code, that in cases like
this a temporary variable is always used, e.g.,
	...
	complex tempf
	tempf = (10,10)
	tempf = x * conjg(y) + tempf
	fred = tempf
	return
	end.

Regards,
                            Michael M. Meyer
                      Statistics/Academic Computing
                       Carnegie Mellon University.

mikem+@andrew.cmu.edu (Michael Meyer) (10/04/89)

I have received numerous replies about my fortran question, viz. is the
following code fragment valid.
>	complex function fred(x,y)
>	complex x,y
>	fred=(10,10)
>	fred= x*conjg(y) + fred
>	return
>	end

Thanks to all who replied.
Some claim it is NOT (!), but the most convincing arguments claim it is.
 My prior opinion was that the code was acceptable, and the compiler was
broken.  I'm now even more convinced of that.
Here are two relevant citations from the fortran standard.
> Excerpts from mail: 3-Oct-89 Re: Is this valid fortran Randall
> Mercer@uxc.cso.u (1388)

> From section 15.5.1 of the Fortran 77 Ansi Standard:

> 	During every execution of the external function
> 	this variable [they are referring to the function name]
> 	must become defined and, once defined, may be referenced
> 	or become redefined.


> Excerpts from mail: 3-Oct-89 Re: Is this valid fortran Mike
> Lipsie@pyrps5.pyram (1352)

> Yes.  ANSI X3.9-1978 15.5.3 states

>   Within a function subprogram, the symbolic name of a 
>   function specified by a FUNCTION or ENTRY statement must not
>   appear in any other nonexecutable statement, except a type-
>   statement.  In an executable statement, such a name may
>   appear only as a variable.

khb%chiba@Sun.COM (chiba) (10/04/89)

In article <AZ_8kVK00YU5I=wkRM@andrew.cmu.edu> mikem+@andrew.cmu.edu (Michael Meyer) writes:
>Hi:
>Could someone please tell me if the following function is valid fortran?
> The code does compile (but produced execution errors) on the Decstation
>3100.  
>	complex function fred(x,y)
>	complex x,y
>	fred=(10,10)
>	fred= x*conjg(y) + fred
>	return
>	end
>
>My question is whether it is allowable to treat the function name (fred)
>as a variable in the body of the function.  Is is allowable to update
>the value of fred?

Page 15-7 of 3.9-1978

"...the symbolic name of a function subprogram or an associated entry
name of the same type _must_ (emphasis added) appear as a variable
name in the function subprogram. During every execution of the
external function, this variable must become defined and, once
defined, may be referenced or become redefined ..."

So your code is legal. If memory serves, DEC (via MIPS :>) supports
recursive calls, and does it as the default case ... perhaps the fred
= f(x) + fred is incidentally calling itself or something equally
evil.

This sort of thing is often broken in compilers; so some folks prefer
to limit their exposure by using temporaries.
Keith H. Bierman    |*My thoughts are my own. !! kbierman@sun.com
It's Not My Fault   |	MTS --Only my work belongs to Sun* 
I Voted for Bill &  | Advanced Languages/Floating Point Group            
Opus                | "When the going gets Weird .. the Weird turn PRO"