(j3.2006) Restrictions on side-effects for (non pure) functions?
Wed Apr 15 10:51:09 EDT 2015
I client sent 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.
Before we file a bug report, I?m concerned that the abuse of side-effects is violating some prohibition in the standard. I?ve found several vague but ominous warnings on various websites, but have not found any relevant language in the latest standard.
Aside from the dubious programming practice - is the following a standard conforming code?
INTEGER FUNCTION next(cnt)
INTEGER, INTENT(INOUT) :: cnt
cnt = cnt + 1
next = cnt
END FUNCTION next
END MODULE belt_and_suspenders
CHARACTER(LEN=64), DIMENSION(2) :: c
INTEGER :: cntc
cntc = 0
c(next(cntc)) = 'a'
END PROGRAM tryit
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the J3