(j3.2006) Restrictions on side-effects for (non pure) functions?
Wed Apr 15 11:36:31 EDT 2015
This discussion has occurred before and there (certainly)
are differences of opinion. Mine is that if you read the
standard literally, *no* function side effect can be
counted on to have any effect. I'll dig up the references
again if necessary.
In other words, the programmer should not expect any
particular behavior when writing the code given. What
an implementor does to please as many customers as
possible is another matter.
On Wed, Apr 15, 2015 at 7:51 AM, Tom Clune <Thomas.L.Clune at nasa.gov> wrote:
> 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
> 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
> J3 mailing list
> J3 at mailman.j3-fortran.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the J3