0

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) :: OPTIONgfortranを使用しようとすると、 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して削除すると、.POINTERError: Component at (1) must have the POINTER attribute

4

2 に答える 2

0

試す:

   type, bind(c) :: OPTION
      character(c_char) :: option
      character(c_char) :: arg
      type(c_ptr) :: next
      type(c_ptr) :: previous
   end type OPTION

Fortran の C ポインターは、実際にはポインターとしてではなく、完全に別の型として扱われます。C_F_POINTERそれらを最大限に活用するには、Fortran ポインターに変換する必要があります。

于 2013-03-18T20:14:37.097 に答える
0

次の型を介して C 型ポインターを使用できますtype(c_ptr)

module resources
  use iso_c_binding
  implicit none
  type, bind(c) :: OPTION
    character(c_char) :: option
    character(c_char) :: arg
    type(c_ptr) :: next
    type(c_ptr) :: previous
  end type OPTION
end module resources
于 2013-03-18T20:14:37.730 に答える