jim@doctor.chem.yale.edu (James F. Blake) (10/08/90)
I want to use malloc for a two dimensional array, but I'm getting strange
results. The following test program illustrates the problem.
program test
pointer (p,v(1,1))
integer i, j, k
real v
p = malloc(1000)
k = 0
do i = 1, 2
do j = 1, 3
k = k + 1
v(i,j) = k
enddo
enddo
do i = 1, 2
do j = 1, 3
write(*,*) i, j, v(i,j)
enddo
enddo
call free(p)
stop
end
This code produces the following output from FORTRAN 1.3 and SunOS4.0.3 on
a Sparcstation I.
1 1 1.00000
1 2 4.00000
1 3 5.00000
2 1 4.00000
2 2 5.00000
2 3 6.00000
If I allocate the memory and then pass the array (v) to a subroutine, all
seems to work fine. Any help would be greatly appreciated.
Jimbliss@sp64.csrd.uiuc.edu (Brian Bliss) (10/27/90)
> pointer (p,v(1,1))
try pointer (p,v(10,10))
if v is dimensioned to v(1,*), then v(1,3) is the same memory location as
v(2,2), and v(1,2) is the same memory location as v(2,1), when not
checking for dimension bound overflow. Not that i've ever seen or used
the FORTRAN pointer construct.
bb