Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rice!rice!sun-spots-request From: jim@doctor.chem.yale.edu (James F. Blake) Newsgroups: comp.sys.sun Subject: Apparent problem with malloc(3F) Keywords: Miscellaneous Message-ID: <1990Oct7.224305.28984@rice.edu> Date: 7 Oct 90 21:30:00 GMT Sender: sun-spots-request@rice.edu Organization: Sun-Spots Lines: 39 Approved: Sun-Spots@rice.edu Originator: spots@walhalla.rice.edu X-Sun-Spots-Digest: Volume 9, Issue 331, message 9 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. Jim