我的目标是调用一个 C 函数来分配 FORTRAN 动态数组(这对整数、实数、逻辑已经很好地工作)。但是我在使用 gfortran 编译器、字符串和公共块时遇到了麻烦。这是我的障碍的提炼:
subroutine sub1()
character(len=:), pointer :: local
character(len=:), pointer :: comm
common /commie/ comm
comm = local
return
end
出于某种原因,将这样的指针放入公共块会混淆 gfortran:
ghart@el9$ gfortran sub1.f
sub1.f:6:72:
6 | comm = local
|
1
internal compiler error: in gfc_conv_variable, at fortran/trans-expr.c:3036
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
ghart@el9$ gfortran --version
GNU Fortran (GCC) **11.3.1** 20220421 (Red Hat 11.3.1-2)
多年来...
ghart@el8$ gfortran sub1.f
sub1.f:6:0:
comm = local
internal compiler error: in gfc_conv_variable, at fortran/trans-expr.c:2726
....
ghart@el8$ gfortran --version
GNU Fortran (GCC) **8.5.0** 20210514 (Red Hat 8.5.0-10)
ghart@el7$ gfortran sub1.f
sub1.f: In function ?sub1?:
sub1.f:6:0: internal compiler error: in gfc_conv_variable, at fortran/trans-expr.c:1796
comm = local
^
ghart@el7$ gfortran --version
GNU Fortran (GCC) **4.8.5** 20150623 (Red Hat 4.8.5-44)
(可能是这个:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55735)
但我真正的问题是:是否有动态大小的字符串数组的替代定义(我可以放在一个公共块中)?我所需要的只是声明,它允许现有的 FORTRAN 代码使用如下内容:
character(kind=ucs4, len=xxx) stringarray1(yyy)
按原样工作,但不是这个:
character(kind=ucs4, len=:) stringarray1(:)
要添加更多上下文,这里是整数的工作代码:
SUBROUTINE shob_arrI(ptr, decl, sz, grp)
USE ISO_C_BINDING
integer, pointer :: ptr(:)
character*(*) decl
integer*8 sz
integer, pointer :: grp
END SUBROUTINE shob_arrI
....
integer, pointer :: grpX
integer, pointer :: i1(:)
common /grpX/ i1
call shob_arrI(i1, 'integer i1(7)', 0_8, grpX)
shob_arrI 是一个 C 函数,它解析定义(“整数 i1(7)”),构建 gfortran GFC_ARRAY_DESCRIPTOR 结构,并将实际数组数据区域映射到共享内存文件(这是为了多进程访问共享数组) .
所以我要找的是字符串数组对应的“整数,指针:: ptr(:)”声明