For Programmers: Free Programming Magazines  


Home > Archive > Fortran > January 2008 > a question about C binding









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author a question about C binding
fj

2008-01-15, 7:16 pm

I tried to pass a subroutine by argument to a C routine. I found two
solutions for declaring the C routine :

INTERFACE
SUBROUTINE c_routine(proc) BIND(C,name="c_routine")
USE iso_c_binding
TYPE(c_funptr),VALUE,INTENT(in) :: proc
END SUBROUTINE
END INTERFACE

or :

INTERFACE
SUBROUTINE c_routine(proc) BIND(C,name="c_routine")
EXTERNAL :: proc
END SUBROUTINE
END INTERFACE

Both solutions are OK with several compilers like g95, ifort or
gfortran. The second one is more convenient because it does not need
the use of the function C_FUNLOC which translates a FORTRAN procedure
into a TYPE(c_funptr).

I have no doubt about the first solution. But is the second one valid
too ?
fj

2008-01-18, 8:13 am

On 15 jan, 20:37, fj <francois.j...@irsn.fr> wrote:
> I tried to pass a subroutine by argument to a C routine. I found two
> solutions for declaring the C routine :
>
> INTERFACE
> SUBROUTINE c_routine(proc) BIND(C,name="c_routine")
> USE iso_c_binding
> TYPE(c_funptr),VALUE,INTENT(in) :: proc
> END SUBROUTINE
> END INTERFACE
>
> or :
>
> INTERFACE
> SUBROUTINE c_routine(proc) BIND(C,name="c_routine")
> EXTERNAL :: proc
> END SUBROUTINE
> END INTERFACE
>
> Both solutions are OK with several compilers like g95, ifort or
> gfortran. The second one is more convenient because it does not need
> the use of the function C_FUNLOC which translates a FORTRAN procedure
> into a TYPE(c_funptr).
>
> I have no doubt about the first solution. But is the second one valid
> too ?


In fact, the second form is not accepted by gfortran because each
argument must have a C type when BIND(C) is required.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com