(j3.2006) Restrictions on side-effects for (non pure) functions?
Tom Clune
Thomas.L.Clune
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?
MODULE belt_and_suspenders
CONTAINS
INTEGER FUNCTION next(cnt)
INTEGER, INTENT(INOUT) :: cnt
cnt = cnt + 1
next = cnt
END FUNCTION next
END MODULE belt_and_suspenders
PROGRAM tryit
USE belt_and_suspenders
IMPLICIT NONE
CHARACTER(LEN=64), DIMENSION(2) :: c
INTEGER :: cntc
cntc = 0
c(next(cntc)) = 'a'
WRITE(6,*) cntc
END PROGRAM tryit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20150415/a350ed93/attachment.html
More information about the J3
mailing list