Pointer to allocatable array
From: Douglas Cox (tcc_at_sentex.net)
Date: 12/22/03
- Next message: beliavsky_at_aol.com: "history of Fortran -- books"
- Previous message: G.F. Thomas: "FP Summation"
- Next in thread: Greg Lindahl: "Re: Pointer to allocatable array"
- Reply: Greg Lindahl: "Re: Pointer to allocatable array"
- Reply: Herman D. Knoble: "Re: Pointer to allocatable array"
- Reply: Richard Maine: "Re: Pointer to allocatable array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 21 Dec 2003 21:44:48 -0500
The output from the code below varies depending on which compiler was
used. Four compilers, four different results. Which is correct?
Douglas Cox
$ cat testap.f90
program testap
integer, allocatable, target :: t(:)
integer, pointer :: p(:)
allocate(t(4))
t = (/ 1,2,3,4 /)
p => t
print *, p
deallocate(t)
allocate(t(10))
t = (/ 11,12,13,14,15,16,17,18,19,20 /)
print *, p
deallocate(t)
allocate(t(2))
t = (/ 100,200 /)
print *, p
deallocate(t)
end program testap
$ g95 -o testap testap.f90
$ ./testap
1 2 3 4
11 12 13 14 15 16 17 18 19 20
100 200
$ f90 -o testap testap.f90
Pacific-Sierra Research vf90 Personal V3.4N3 20:46:44 12/21/03
f90 to f77
program testap
$ ./testap
1 2 3 4
11 12 13 14
100 200 13 14
$ ifort -o testap testap.f90
$ ./testap
1 2 3 4
0 2 3 4
0 2 3 4
$ gfortran -o testap testap.f90
$ ./testap
1 2 3 4
11 12 13 14
100 200 0 0
$
- Next message: beliavsky_at_aol.com: "history of Fortran -- books"
- Previous message: G.F. Thomas: "FP Summation"
- Next in thread: Greg Lindahl: "Re: Pointer to allocatable array"
- Reply: Greg Lindahl: "Re: Pointer to allocatable array"
- Reply: Herman D. Knoble: "Re: Pointer to allocatable array"
- Reply: Richard Maine: "Re: Pointer to allocatable array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]