Pointers to array sections - is this guaranteed to work?

From: Arjen Markus (arjen.markus_at_wldelft.nl)
Date: 08/25/04


Date: Wed, 25 Aug 2004 13:39:40 +0200

Hello,

I am trying to find out whether a program like the one below conforms to
the standard.

The problem:
- I want to register, for later use, pointers to arrays
- The problem is that these arrays may be larger than what is
  useful to me.
- So I want to store a pointer to the array section (!) that
  holds the relevant information - I do not have to worry
  about the extra bits anymore.

My question: is the program below guaranteed to work or
am I somehow relying on pointers to temporary copies?

(Note: I have tried two very different compilers, one
rahter old, and the results are encouraging: the
program works).

Regards,

Arjen

--------

module register
   real, private, pointer, dimension(:,:) :: twod_arr

contains

subroutine reg(array)
   real, target, dimension(:,:) :: array

   twod_arr => array
end subroutine

subroutine print
   write(*,'(1x,10f10.3)') twod_arr
end subroutine

end module

program tryit
   use register

   real, dimension(-10:20,-3:33) :: array

   do j = -3,33
      do i = -10,20
         array(i,j) = 100.0*j + i
      enddo
   enddo

   call reg( array(1:10,2:10) )

   !
   ! Try to make sure that there is nothing left in the stack
   ! or something that gives a false picture
   !
   call messup

   call print

contains

subroutine messup
   real, dimension(1:10000) :: work

   work = 1.0

   write(*,*) 'sum:',sum(work)

   array(1,3) = -1.0
   array(2,:) = -2.0
end subroutine

endprogram



Relevant Pages

  • Re: Pointer problem in module
    ... particular, they are automatic arrays. ... subroutine starts and deallocated when the subroutine returns. ... Your pointers point into these temporary arrays. ...
    (comp.lang.fortran)
  • Re: turbo pascal question
    ... > values that could fit in a register. ... Integers, pointers, but not ... > records or arrays. ...
    (comp.lang.pascal.delphi.misc)
  • Re: turbo pascal question
    ... > values that could fit in a register. ... Integers, pointers, but not ... > records or arrays. ...
    (comp.lang.pascal.delphi.misc)
  • Re: F.03 C Interoperability doubt. Argument types
    ... from the net) that i need to call from my fortran subroutine written ... to pointers in my C subroutine AND create pointers in my f.03 ... those variables and arrays in my f.03 subroutine as they are in the C ...
    (comp.lang.fortran)
  • F.03 C Interoperability doubt. Argument types
    ... from the net) that i need to call from my fortran subroutine written ... int natoms,int step,real time, ... to pointers in my C subroutine AND create pointers in my f.03 ... those variables and arrays in my f.03 subroutine as they are in the C ...
    (comp.lang.fortran)