【发布时间】:2013-03-18 18:40:00
【问题描述】:
在 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。
【问题讨论】:
标签: c struct interop fortran fortran-iso-c-binding