All pastes #2085459 Raw Edit

iso_c_binding test

public text v1 · immutable
#2085459 ·published 2011-09-29 23:16 UTC
rendered paste body
module testCommon
 interface
  subroutine fooC(outVal, ioArr) bind(C, name="fooC")
    use iso_c_binding
    integer (c_int), intent(inout) :: outVal
    type (c_ptr), value :: ioArr  ! have also tried intent(inout) and without attributes
  end subroutine fooC
 end interface
end module

subroutine fooF() bind(C, name='fooFortran')
  use iso_c_binding
  use testCommon
  implicit none

  real (c_double), target, allocatable :: shp(:,:,:)
  integer :: arrLen = 3

  allocate(shp(arrLen,arrLen,arrLen))
  shp(1,:,1) = 1.111
  write(*,*) 'Fortran: shp(1,:,1) before fooC', shp(1,:,1)
  call fooC(arrLen, c_loc(shp(1,:,1)) )
  write(*,*) 'Fortran: shp(1,:,1) after fooC', shp(1,:,1)

  deallocate(shp)
end