(j3.2006) Restrictions on side-effects for (non pure) functions?
Malcolm Cohen
malcolm
Wed Apr 15 20:55:41 EDT 2015
<<<
an example that appears to produce incorrect answers under gfortran, but the
expected results on other compilers. (Intel, NAG). A function with a side
effect is used to return an index for an array reference. This works if the
function is evaluated once, but it appears to be evaluated twice with gfortran.
...
c(next(cntc)) = 'a'
>>>
I agree with Bill. There is one function reference in this statement. That
means there is at most one reference to the function.
The standard says that you cannot rely on the function being evaluated at all.
"It is not necessary for a processor to evaluate all of the operands of an
expression, or to evaluate entirely each operand, if the value of the expression
can be determined otherwise."
However there is no leeway for additional function evaluations, unless you take
the perverse interpretation that "mathematical equivalence" means you can insert
" + 0*next(cntc)" into every expression. This interpretation is sufficiently
ridiculous that we have not yet found it necessary to explicitly outlaw it.
Cheers,
--
................................Malcolm Cohen, Nihon NAG, Tokyo.
More information about the J3
mailing list