C_FUNLOC — 프로시저의 C 주소 얻기
C_FUNLOC — 프로시저의 C 주소 얻기
Fortran 프로시저를 C 코드에 함수 포인터로 넘겨야 할 때가 있어요. C_FUNLOC은 인자의 C 주소를 알아내는 조회 함수예요.
본문
RESULT = C_FUNLOC(X)
설명(Description)
C_FUNLOC(X)는 인자의 C 주소를 결정해요.
분류(Class)
조회 함수(Inquiry function)
인자(Arguments)
X— 상호운용 가능한(interoperable) 함수 또는 그런 함수를 가리키는 포인터예요.
반환값(Return value)
반환값은 C_FUNPTR 타입이며 인자의 C 주소를 담아요.
예제
module x
use iso_c_binding
implicit none
contains
subroutine sub(a) bind(c)
real(c_float) :: a
a = sqrt(a)+5.0
end subroutine sub
end module x
program main
use iso_c_binding
use x
implicit none
interface
subroutine my_routine(p) bind(c,name='myC_func')
import :: c_funptr
type(c_funptr), intent(in) :: p
end subroutine
end interface
call my_routine(c_funloc(sub))
end program main
bind(c)로 선언된 서브루틴 sub의 주소를 c_funloc(sub)으로 얻어, C에서 준비한 my_routine에 함수 포인터로 넘기는 예제예요.
표준(Standard)
Fortran 2003 이상
같이 보기
C_ASSOCIATED — C 포인터의 상태, C_LOC — 객체의 C 주소 얻기, C_F_POINTER — C를 Fortran 포인터로 변환, C_F_PROCPOINTER — C를 Fortran 프로시저 포인터로 변환