ambiguous ?

Richard O'Keefe ok at cs.mu.oz.au
Fri Oct 20 14:53:05 AEST 1989


In article <6591 at ficc.uu.net>, peter at ficc.uu.net (Peter da Silva) writes:
> 	INTEGER FUNCTION RAND(NEWSEED)
> 	INTEGER SEED
> 	INTEGER NEWSEED

The code sketch which follows relies on the value of SEED being preserved
between calls.  However, a Fortran compiler is allowed to implement local
variables _either_ as "static" _or_ as "auto", at whim.  If you need the
equivalent of C "static" variables, you have to say

	SAVE SEED

(Strictly speaking this may also be needed for COMMON blocks, but it is
most unlikely to give you trouble on a system without overlays.)

> 	CALL HOOPY(RAND(0), RAND(0), RAND(0))

A Fortran compiler is explicitly permitted to compile this as if you
had written
	ITEMP = RAND(0)
	CALL HOOPY((ITEMP), (ITEMP), (ITEMP))

> Will this program produce the same output on different machines?
No.

> Is this guaranteed?

An even simpler example:
	ITEMP = 0*RAND(0)
Whether this calls RAND or not is up to the compiler.



More information about the Comp.lang.c mailing list