长度参数化的传递给类型绑定过程的对象有gfortran抱怨 [英] Length-parameterized passed object to type-bound procedure has gfortran complain

查看:103
本文介绍了长度参数化的传递给类型绑定过程的对象有gfortran抱怨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Fortran,我想将数组和子例程封装为一种类型.问题似乎出在自对象的类型定义中.

I'm learning Fortran and I'd like to encapsulate an array and a subroutine in a type. The problem appears to be in the type definition of the self-object.

这是我想出的最小测试用例:

This is the minimal test case I came up with:

module testing
  implicit none

  type test(para)
    integer, len :: para
    real, dimension(para) :: weights

  contains
    procedure :: testing => testing_test
  end type
contains
  subroutine testing_test(self)
    class(test(*)) :: self
  end subroutine
end module

使用gfortran进行编译会引发以下错误:

Compiling this with gfortran raises this error:

module_test.f08:9:23:

  procedure :: testing => testing_test
          1
Error: Argument ‘self’ of ‘testing_test’ with PASS(self) at (1) must be of the derived-type ‘test’

它在固定数组长度(因此type%para不存在)时起作用

It works when the array-length is fixed (so type%para doesn't exist)

我要做的事情(带有可变大小的数组和绑定过程的类型)显然是不可能的,还是我缺少有关虚拟参数定义的内容?

Is what I'm trying to do (type with array of variable size and bound procedure) plain impossible or am I missing something regarding dummy argument definition?

推荐答案

感谢@Rodrigo的想法,我终于找到了这个错误(和补丁): https://gcc.gnu.org/bugzilla/show_bug.cgi?id= 82943

Thanks to @Rodrigo for the idea, I finally found this bug (and patch): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82943

要解决此问题,请下载源代码,应用提到的补丁程序并编译自己的gfortran. (或者等到它在存储库中)

To fix the issue, download the source, apply the mentioned patch and compile your own gfortran. (Or wait until it's in the repositories)

这篇关于长度参数化的传递给类型绑定过程的对象有gfortran抱怨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆