2.2.2 C 绑定模块 Fortran 2003 标准提供了一种引用 C 语言过程的方式。ISO_C_BINDING模块按内模块函数形式定义了三个支持过程。访问这些函数需要在调用例程中使用 USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC, C_PTR, C_ASSOCIATED 。该模块中定义的过程如下...
ios_c_binding中除了常数之外,还定义了几个函数,以及c语言指针类型type(c_ptr),函数指针类型type(c_funptr),可惜的是它们都并不区分具体的指针类型,只能说可堪一用吧。 c_loc和c_funloc函数将fortran的指针与函数指针转化为type(c_ptr)和type(c_funcptr)。c_f_pointer和c_f_procpointer则将c语言的指针赋...
integer(c_int) function func2(pt, n) bind(c, name="test") importimplicitnone integer(c_int), intent(in), value:: n type(c_ptr), value:: pt end function endinterfacetype(c_ptr) :: a1 integer(c_int), target:: abc(5) integer:: i abc= [12,12,35,67,11] a1= c_loc(abc(...
2.2.2 C 绑定模块Fortran 2003 标准提供了一种引用 C 语言过程的方式。ISO_C_BINDING 模块按内模块函数形式定义了三个支持过程。访问这些函数需要在调用例程中使用 USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC, C_PTR, C_ASSOCIATED。该模块中定义的过程如下...
<- NULL-terminated string constant get_string = C_LOC(fortstring) end function get_string // c_string.c: uses a char* to point at the address returned by 'get_string' #include <stdio.h> #include <string.h> #include <stdlib.h> char *get_string(void); // <- Fortran fcn ...
of the CUDA_C_Programming_Guide. Managed memory provides a common address space, and migrates data between the host and device as it is used by each set of processors. On the host side, the data is resident in host main memory. On the device side, it is accessed as resident in ...
only: elemname, nbelem implicit none integer(c_int), INTENT(IN), value :: i character(len=21,kind=c_char) :: returnval returnval=''//C_NULL_CHAR if(i<=nbelem .and. i>0)returnval=trim(elemname(i))//C_NULL_CHAR get_elem_name = C_LOC(returnval) end f...
C_LOC (X)is an inquiry function that returns the C address ofX. Xis permitted to be a procedure that is interoperable (see para. 5) or a variable that has theTARGETattribute and is either interoperable or is an allocated allocatable variable that has interoperable type and type parameters....
integer(c_int), parameter :: fftw_estim_input=1 real(c_double), dimension(n) :: in, out type(c_ptr) :: plan in = [1.0, 2.0, 1.0, -1.0, 1.5, 2.1, 3.2, 0.5] out = 0.0 plan = fftw_plan_dft_1d(n, c_loc(in), c_loc(out), c_int(FFTW_BACKWARD), c_int(FFTW_ESTIMATE...
First, here is the Fortran routine that takes two numbers, adds them together, puts the result into a structure and returns a pointer to the structure using "c_loc"; a second subroutine receives the pointer, accesses the result and sends it back as an ordinary number: [cpp]modu...