Apparent problem with malloc(3F)

James F. Blake jim at doctor.chem.yale.edu
Mon Oct 8 07:30:00 AEST 1990


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



More information about the Comp.sys.sun mailing list