Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.c Subject: Re: ambiguous ? Message-ID: <14096@lanl.gov> Date: 20 Oct 89 21:31:17 GMT References: <6591@ficc.uu.net> Organization: Los Alamos National Laboratory Lines: 33 From article <6591@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva): > [... RAND defined with the usual side effects ...] > And then: > > I = RAND(very carefully designed seed) > CALL HOOPY(RAND(0), RAND(0), RAND(0)) > > Will this program produce the same output on different machines? Is this > guaranteed? The call to HOOPY is not standard conforming. The relevant part of the standard is: 6.6.2 [...] In a statement that contains more than one function reference, the value provided by each function reference must be independent of the order chosen by the processor for evaluation of the function references. As I have said before, Fortran isn't perfect. In this case it is overly restrictive in the same way that C under-restrictive. I would prefer to be able to explicitly declare whether a function has side-effects and the allow the processor to optimize all calls to side-effect free functions. For functions _with_ side-effects, the 'left-to-right' rule could apply with no particular hardship. This is different than the issue under discussion with C though. Here, the arguments may have side-effects _without_ even calling a function. In this case, any compiler smart enough to usefully optimize the argument preparation is alse smart enough to detect the dependencies among arguments and enforce an order among them. I see no reason that the language standard couldn't require this to be done.