This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
C binding
- From: Salvatore Filippone <salvatore dot filippone at uniroma2 dot it>
- To: Fortran at gcc dot gnu dot org
- Date: Wed, 19 Sep 2007 13:33:45 +0200
- Subject: C binding
- Reply-to: salvatore dot filippone at uniroma2 dot it
Hi,
I have started playing with the C binding module in GCC 4.3, and I
immediately encountered a problem. My copy of MR&C says that the c_loc
intrinsic may be applied to (case ib) "an allocated allocatable variable
that has the target attribute and is not an array of zero size",
which I take to mean that the code shown below under the if(.true.) is
legal, and yet gfortran refuses it.
Therefore it may be that :
1. I got it wrong
2. It's something not implemented yet
3. It's a bug
Comments?
Thanks a lot
Salvatore
-------------------output------------------------
[sfilippo@localhost bugtest]$ /usr/local/gcc43/bin/gfortran -c
c_vhandle_mod.f90
c_vhandle_mod.f90:16.40:
get_double_vector_address = c_loc(dbv_pool(handle)%v)
1
Error: Parameter 'dbv_pool' to 'c_loc' at (1) must be a scalar
[sfilippo@localhost bugtest]$ /usr/local/gcc43/bin/gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.3-20070831/configure --prefix=/usr/local/gcc43
--with-mpfr=/home/travel/GCC/BUILDS/mpfr
--with-gmp-lib=/home/travel/GCC/BUILDS/gmp/lib/
--with-gmp=/home/travel/GCC/BUILDS/gmp
Thread model: posix
gcc version 4.3.0 20070831 (experimental) (GCC)
[sfilippo@localhost bugtest]$ /usr/local/gcc43/bin/gfortran -c
c_vhandle_mod.f90
c_vhandle_mod.f90:16.40:
get_double_vector_address = c_loc(dbv_pool(handle)%v)
1
Error: Parameter 'dbv_pool' to 'c_loc' at (1) must be a scalar
-------------------------------------- c_vhandle_mod-------
module c_vhandle_mod
use iso_c_binding
type double_vector_item
real(kind(1.d0)), allocatable :: v(:)
end type double_vector_item
type(double_vector_item), allocatable, target :: dbv_pool(:)
real(kind(1.d0)), allocatable, target :: vv(:)
contains
type(c_ptr) function get_double_vector_address(handle)
integer(c_int), intent(in) :: handle
if (.true.) then ! The ultimate component is an allocatable target
get_double_vector_address = c_loc(dbv_pool(handle)%v)
else
get_double_vector_address = c_loc(vv)
endif
end function get_double_vector_address
end module c_vhandle_mod