Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
525 views
in Technique[技术] by (71.8m points)

fortran - Length-parameterized passed object to type-bound procedure has gfortran complain

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

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’

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...