Pointers 具有iso_c_绑定的diffptr_t fortran
我想在fortran中使用iso_c_绑定进行一种区分。内存距离结果必须是有符号整数Pointers 具有iso_c_绑定的diffptr_t fortran,pointers,fortran,fortran-iso-c-binding,Pointers,Fortran,Fortran Iso C Binding,我想在fortran中使用iso_c_绑定进行一种区分。内存距离结果必须是有符号整数 type(c_ptr) :: start,ref type(c_int) :: res start=c_loc(my_struct%a) ref=c_loc(my_struct%b%c) res=start-ref 编译错误: This binary operation is invalid for this data type. An arithmetic or LOGICAL type is requir
type(c_ptr) :: start,ref
type(c_int) :: res
start=c_loc(my_struct%a)
ref=c_loc(my_struct%b%c)
res=start-ref
编译错误:
This binary operation is invalid for this data type.
An arithmetic or LOGICAL type is required in this context.
谢谢您不能在标准Fortran中执行指针算术。您必须依赖于指针和整数之间依赖于处理器的二进制对应关系 此外,Fortran中没有无符号整数
type(c_ptr) :: start,ref
integer(c_int) :: res
start = c_loc(my_struct%a)
ref = c_loc(my_struct%b%c)
res = int( transfer(start, 1_c_intptr_t) - transfer(ref, 1_c_intptr_t) , c_int)
如果指针值大于带符号的
c\u intptr\u t
的最大正值,则可能会出现问题。您无法在标准Fortran中执行指针算术。您必须依赖于指针和整数之间依赖于处理器的二进制对应关系
此外,Fortran中没有无符号整数
type(c_ptr) :: start,ref
integer(c_int) :: res
start = c_loc(my_struct%a)
ref = c_loc(my_struct%b%c)
res = int( transfer(start, 1_c_intptr_t) - transfer(ref, 1_c_intptr_t) , c_int)
如果指针值大于带符号的c_intptr\u t
的最大正值,则可能会出现问题