(j3.2006) Restrictions on side-effects for (non pure) functions?
Walt Brainerd
walt.brainerd
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
> 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
>
>
>
>
>
>
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
--
Walt Brainerd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20150415/b1fac461/attachment-0002.html
More information about the J3
mailing list