在 Fortran 中定义这个递归 C 结构的正确方法是什么?
struct OPTION {
char option;
char *arg;
struct OPTION *next;
struct OPTION *previous;
};
我写了这个 Fortran 代码:
module resources
use iso_c_binding
implicit none
type :: OPTION
character(c_char) :: option
character(c_char) :: arg
type(OPTION), pointer :: next
type(OPTION), pointer :: previous
end type OPTION
end module resources
这可以编译,但我认为这是错误bind(c)
的,因为缺少类型定义。如果我尝试将type, bind(c) :: OPTION
gfortran 归咎于Error: Component 'next' at (1) cannot have the POINTER attribute because it is a member of the BIND(C) derived type 'option' at (2)
.
如果我保留type, bind(c) :: OPTION
并删除POINTER
我得到的属性Error: Component at (1) must have the POINTER attribute
。