(j3.2006) F08/0099
Van Snyder
Van.Snyder
Wed Oct 23 15:50:09 EDT 2013
In 13-298r2, the answer to F08/0099, which concerned the following
subroutine
subroutine Wobbly ( N )
integer, volatile :: N
integer :: A ( n, n )
integer :: B ( n * n )
print *, size(a) == size(b), size(a,1) == size(a,2)
end subroutine Wobbly
was essentially "each specification expression is independent, so it's
not required to print "T T".
Consider the following subroutine in its place:
subroutine Wobbly ( N )
integer, volatile :: N
integer :: A(2*n)
print *, 'Size of A is ', &
trim(merge('even','odd ',mod(size(a,2)==0))))
end subroutine Wobbly
It seems that the obvious answer is "It always prints 'Size of A is
even'.
But 7.1.5.2.4p2 says
Once the interpretation of a numeric intrinsic operation is
established, the processor may evaluate any mathematically equivalent
expression, provided that the integrity of parentheses is not
violated.
This means that a processor might decide that "n+n" is less expensive
than "2*n", and use that instead.
Is the processor allowed to fetch the volatile N twice, perhaps getting
an even value the first time and an odd value the second time, thereby
printing 'Size of A is odd'?
If not, should we amend 7.1.5.2.4p2 to prohibit transformations that
change the number of references to volatile variables (or maybe only the
ones that increase the number of references), at least in specification
expressions?
More information about the J3
mailing list