Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance 在gfortran中,将(1:n)与继承类一起使用非常奇怪_Inheritance_Fortran_Gfortran_Fortran2003 - Fatal编程技术网

Inheritance 在gfortran中,将(1:n)与继承类一起使用非常奇怪

Inheritance 在gfortran中,将(1:n)与继承类一起使用非常奇怪,inheritance,fortran,gfortran,fortran2003,Inheritance,Fortran,Gfortran,Fortran2003,我一直在用fortran90客观地更新一个较旧的程序 我遇到了一个非常奇怪的继承对象行为: 例如: module try_mod implicit none type, public :: Inner_t integer :: i real :: r end type Inner_t type, public, extends(Inner_t) :: InnerSpec_t integer :: j end type InnerSpec_t type, public :: O

我一直在用fortran90客观地更新一个较旧的程序 我遇到了一个非常奇怪的继承对象行为: 例如:

module try_mod

implicit none

type, public :: Inner_t
  integer :: i
  real :: r
end type Inner_t

type, public, extends(Inner_t) :: InnerSpec_t
  integer :: j
end type InnerSpec_t

type, public :: Outer_t
  integer :: nelem
  class( Inner_t ), allocatable, dimension(:) :: elem

contains
  procedure :: init => initOuter

end type Outer_t


contains

 subroutine initOuter(this)
  class(Outer_t), intent(inout) :: this
  integer :: i, suma, k

  this%nelem = 4

  allocate( InnerSpec_t :: this%elem(1:this%nelem) )


  this%elem(1:2)%i = -100
  this%elem(3:4)%i = -200


  print*, '1st: ', this%elem(1:this%nelem)%i
  print*, '2nd: ', this%elem(1)%i, this%elem(2)%i, this%elem(3)%i, this%elem(4)%i

  this%elem(1)%i = 91 
  this%elem(2)%i = 92 
  this%elem(3)%i = 93
  this%elem(4)%i = 94 
  print*,'3rd: ', this%elem(1:4)%i
  print*,'4th: ', this%elem(1)%i, this%elem(2)%i, this%elem(3)%i, this%elem(4)%i



end subroutine initOuter

end module try_mod 

program adgo
  use try_mod

implicit none

  type( Outer_t ) :: outer

  call outer%init()
end program
如果我用gfortran(4.8或4.9)编译这个程序,我会得到

尽管第一排和第二排(分别为第三排和第四排)应相同。看起来继承对象的内存分配存在一些问题,因为如果我注释变量j的声明(在InnerSpec\t中),就会出现这个问题。 如果使用英特尔fortran编译,一切正常


我是否使用了不恰当的构造?有没有办法让gfortran也能做到这一点

这看起来很像gfortran中的一个bug。我已经提交了这个(PR是“问题报告”)。

乍一看,它确实看起来像一个gfortran bug。你能在下面提交一份公关文件吗?@tkoenig:不幸的是,我不知道该怎么做。。。我必须在那里记帐吗?顺便说一句,PR是什么意思?我最近在PR 65359中查看了这个bug报告,并用gfortran 5.3再次尝试了这个程序,但仍然不起作用。你能解释一下为什么没有人被分配到这个bug中吗?这个例子不知何故是非标准的(没有人使用这样的结构),还是仅仅因为没有人再关心fortran?
 1st:         -100        -100        -200        -200
 2nd:         -100       32751        -200  1852387182
 3rd:           91        -100        -200          93
 4th:           91          92          93          94