Cインターフェースへのバインディング手順#
c_associated#
名前#
c_associated(3) - [ISO_C_BINDING] Cポインタの状態
概要#
result = c_associated(c_prt_1, [c_ptr_2] )
logical function c_associated(c_prt_1, cptr_2)
TYPE,intent(in) ::c_ptr_1
TYPE,intent(in),optional ::c_ptr_2
特性#
c_ptr_1は、c_ptrまたはc_funptr型のスカラーです。
c_ptr_2は、c_ptr_1と同じ型のスカラーです。
戻り値は論理型です。
説明#
c_associated(3)は、Cポインタc_ptr_1の状態、またはc_ptr_1がターゲットc_ptr_2と関連付けられているかどうかを判断します。
オプション#
- c_ptr_1
C NULLポインタであるかどうか、またはc_ptr_2が存在する場合に同じ関連付けを指しているかどうかをテストするためのCポインタ。
- c_ptr_2
c_ptr_1と共有の関連付けをテストするためのCポインタ
結果#
戻り値は論理型です。c_ptr_1がC NULLポインタである場合、またはc_ptr1とc_ptr_2が異なるアドレスを指している場合は.false.になります。
例#
サンプルプログラム
program demo_c_associated
contains
subroutine association_test(a,b)
use iso_c_binding, only: c_associated, c_loc, c_ptr
implicit none
real, pointer :: a
type(c_ptr) :: b
if(c_associated(b, c_loc(a))) &
stop 'b and a do not point to same target'
end subroutine association_test
end program demo_c_associated
標準#
Fortran 2003
関連項目#
c_loc(3)、c_funloc(3)、iso_c_binding(3)
fortran-lang組込み関数の説明
c_f_pointer#
名前#
c_f_pointer(3) - [ISO_C_BINDING] CポインタをFortranポインタに変換
概要#
call c_f_pointer(cptr, fptr [,shape] )
subroutine c_f_pointer(cptr, fptr ,shape )
type(c_ptr),intent(in) :: cprt
type(TYPE),pointer,intent(out) :: fprt
integer,intent(in),optional :: shape(:)
特性#
Fortranポインタfprtは、cptrと相互運用可能でなければなりません。
shapeは、fptrが配列の場合にのみ指定されます。
説明#
c_f_pointer(3)は、ターゲット(Cポインタcptr)をFortranポインタfptrに割り当て、fptrが配列を指している場合はその形状を指定します。
オプション#
- cptr
c_ptr型のスカラー。intent(in)です。
- fptr
cptrと相互運用可能なポインタ。intent(out)です。
- shape
(オプション) intent(in)の整数型のランク1配列。fptrが配列である場合かつその場合にのみ存在する必要があります。サイズはfptrのランクと等しくなければなりません。
例#
サンプルプログラム
program demo_c_f_pointer
use iso_c_binding
implicit none
interface
subroutine my_routine(p) bind(c,name='myC_func')
import :: c_ptr
type(c_ptr), intent(out) :: p
end subroutine
end interface
type(c_ptr) :: cptr
real,pointer :: a(:)
call my_routine(cptr)
call c_f_pointer(cptr, a, [12])
end program demo_c_f_pointer
標準#
Fortran 2003
関連項目#
c_loc(3)、c_f_procpointer(3)、iso_c_binding(3)
fortran-lang組込み関数の説明
c_f_procpointer#
名前#
c_f_procpointer(3) - [ISO_C_BINDING] CプロシージャポインタをFortranプロシージャポインタに変換
概要#
call c_f_procpointer(cptr, fptr)
subroutine c_f_procpointer(cptr, fptr )
type(c_funptr),intent(in) :: cprt
type(TYPE),pointer,intent(out) :: fprt
特性#
説明#
c_f_procpointer(3)は、C関数ポインタcptrのターゲットをFortranプロシージャポインタfptrに割り当てます。
オプション#
- cptr
c_funptr型のスカラー。intent(in)です。
- fptr
cptrと相互運用可能なプロシージャポインタ。intent(out)です。
例#
サンプルプログラム
program demo_c_f_procpointer
use iso_c_binding
implicit none
abstract interface
function func(a)
import :: c_float
real(c_float), intent(in) :: a
real(c_float) :: func
end function
end interface
interface
function getIterFunc() bind(c,name="getIterFunc")
import :: c_funptr
type(c_funptr) :: getIterFunc
end function
end interface
type(c_funptr) :: cfunptr
procedure(func), pointer :: myFunc
cfunptr = getIterFunc()
call c_f_procpointer(cfunptr, myFunc)
end program demo_c_f_procpointer
標準#
Fortran 2003
関連項目#
c_loc(3)、c_f_pointer(3)、iso_c_binding(3)
fortran-lang組込み関数の説明
c_funloc#
名前#
c_funloc(3) - [ISO_C_BINDING] プロシージャのCアドレスを取得
概要#
result = c_funloc(x)
特性#
説明#
c_funloc(3)は、引数のCアドレスを決定します。
オプション#
- x
相互運用可能な関数、またはそのような関数のポインタ。
結果#
戻り値はc_funptr型であり、引数のCアドレスが含まれています。
例#
サンプルプログラム
! program demo_c_funloc and module
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 demo_c_funloc
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 demo_c_funloc
標準#
Fortran 2003
関連項目#
c_associated(3)、c_loc(3)、c_f_pointer(3)、
c_f_procpointer(3)、iso_c_binding(3)
fortran-lang組込み関数の説明
c_loc#
名前#
c_loc(3) - [ISO_C_BINDING] オブジェクトのCアドレスを取得
概要#
result = c_loc(x)
特性#
説明#
c_loc(3)は、引数のCアドレスを決定します。
オプション#
- x
ポインタ属性またはターゲット属性のいずれかを持つ必要があります。coindexedオブジェクトであってはなりません。相互運用可能な型と種類の型パラメータを持つ変数、または長さ型パラメータを持たないスカラーの非多型変数のいずれかである必要があります。
結果#
戻り値はc_ptr型であり、引数のCアドレスが含まれています。
例#
サンプルプログラム
subroutine association_test(a,b)
use iso_c_binding, only: c_associated, c_loc, c_ptr
implicit none
real, pointer :: a
type(c_ptr) :: b
if(c_associated(b, c_loc(a))) &
stop 'b and a do not point to same target'
end subroutine association_test
標準#
Fortran 2003
関連項目#
c_associated(3)、c_funloc(3)、c_f_pointer(3)、
c_f_procpointer(3)、iso_c_binding(3)
fortran-lang組込み関数の説明
c_sizeof#
名前#
c_sizeof(3) - [ISO_C_BINDING] 式のバイトサイズ
概要#
result = c_sizeof(x)
特性#
説明#
c_sizeof(3) は、式xが占める記憶域のバイト数を計算します。
オプション#
- x
引数は、相互運用可能なデータエンティティである必要があります。
結果#
戻り値は整数型で、システム依存のkind `c_size_t`(`iso_c_binding`モジュールから)です。その値は、引数が占めるバイト数です。引数がポインタ属性を持つ場合、指し示される記憶域領域のバイト数が返されます。引数がポインタまたはallocatableコンポーネントを持つ派生型の場合、戻り値にはこれらのコンポーネントが指し示すデータのサイズは含まれません。
例#
サンプルプログラム
program demo_c_sizeof
use iso_c_binding
implicit none
real(c_float) :: r, s(5)
print *, (c_sizeof(s)/c_sizeof(r) == 5)
end program demo_c_sizeof
結果
T
デフォルトのreal変数が異常にパディングされているプラットフォームを使用していない限り、この例は`.true.`を出力します。
標準#
Fortran 2008
参照#
fortran-lang組込み関数の説明