array of pointers using integers
Hi,
I am testing different ways for some structures and I want to know if its possible to use the interfaces "molding" for change the arguments, like an array of pointers using an array of integer(kind=C_INT_PTR).
I am trying with this code and with intel compiler work fine, but I'm not sure if is safe or can produce problems in the optimization process (inlining, perfomance, ...)
!-
! x86_64
#define C_INT_PTR 8
#define REAL_KIND 8
module real_pointer
implicit none
public
type real_t
real(REAL_KIND) :: v1, v2
end type real_t
type real_p
type(real_t), pointer :: p
end type real_p
end module real_pointer
!-
program test_pointer
use real_pointer
integer, parameter :: n = 10
integer(C_INT_PTR), dimension(n):: p_array
real(REAL_KIND),dimension(2,n) :: r_array
integer :: i
interface
integer(C_INT_PTR) function MyLoc( value )
real(REAL_KIND), dimension(:), intent(in) :: value
end function MyLoc
subroutine print_pointer_array( n, i_array )
integer, intent(in) :: n
integer(C_INT_PTR), intent(in) :: i_array(n)
end subroutine print_pointer_array
end interface
do i = 1, n
call random_number(r_array(:,i))
end do
do i = 1, n
p_array(i) = MyLoc(r_array(:,i))
end do
call print_pointer_array(n,p_array)
end program test_pointer
!-
integer(C_INT_PTR) function MyLoc( address )
integer(C_INT_PTR), intent(in) :: address
MyLoc = address
end function MyLoc
!-
subroutine print_pointer_array( n, parray )
use real_pointer
integer,intent(in) :: n
type(real_p), dimension(n), intent(in) :: parray
integer :: i
do i = 1, n
print*,parray(i)%p
end do
end subroutine print_pointer_array
!-
Thanks!

