Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uhccux!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c Subject: Re: ambiguous ? Summary: missing SAVE statement Message-ID: <2476@munnari.oz.au> Date: 20 Oct 89 04:53:05 GMT References: <1989Oct17.203733.23121@utzoo.uucp> <14091@lanl.gov> <6591@ficc.uu.net> Sender: news@cs.mu.oz.au Lines: 30 In article <6591@ficc.uu.net>, peter@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.