Pointers to array sections - is this guaranteed to work?
From: Arjen Markus (arjen.markus_at_wldelft.nl)
Date: 08/25/04
- Next message: Jugoslav Dujic: "Re: Fortran calls a C function that returns a struct"
- Previous message: Arjen Markus: "Re: Fortran calls a C function that returns a struct"
- Next in thread: Michael Metcalf: "Re: Pointers to array sections - is this guaranteed to work?"
- Reply: Michael Metcalf: "Re: Pointers to array sections - is this guaranteed to work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jugoslav Dujic: "Re: Fortran calls a C function that returns a struct"
- Previous message: Arjen Markus: "Re: Fortran calls a C function that returns a struct"
- Next in thread: Michael Metcalf: "Re: Pointers to array sections - is this guaranteed to work?"
- Reply: Michael Metcalf: "Re: Pointers to array sections - is this guaranteed to work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|