ambiguous ?
Jim Giles
jlg at lanl.gov
Sat Oct 21 07:31:17 AEST 1989
>From article <6591 at ficc.uu.net>, by peter at 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.
More information about the Comp.lang.c
mailing list