Suppose I have something like:
real, dimension(:), allocatable :: S
integer, dimension(:) :: idx
...
S = S(idx)
where S
and idx
are properly allocated/initialized before the assignment.
What does the Fortran standard(s) say, if anything, about the memory location (address) of S
? Should it stay in the same place after the assigment? Is it unspecified (up to the compiler to decide)? Does it make a difference if S
is not allocatable
?
Full example:
$ cat test.f90
program test
implicit none
real, dimension(:), allocatable :: S
integer :: i, idx(7) = [1,3,5,7,2,4,6]
allocate(S(size(idx)))
do i=1,size(S)
S(i) = i*i
end do
write(6,*) S
write(6,*) loc(S)
S = S(idx)
write(6,*) S
write(6,*) loc(S)
S(:) = S(idx)
write(6,*) S
write(6,*) loc(S)
deallocate(S)
end program
$ sunf90 -V
f90: Studio 12.6 Fortran 95 8.8 Linux_i386 2017/05/30
$ sunf90 test.f90 ; ./a.out
1.0 4.0 9.0 16.0 25.0 36.0 49.0
37518752
1.0 9.0 25.0 49.0 4.0 16.0 36.0
37519840
1.0 25.0 4.0 36.0 9.0 49.0 16.0
37519840
(assuming loc
gives something related to the address of the array)