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
Fortran 指向派生类型的指针的声明是否可以未定义?_Fortran_Gfortran - Fatal编程技术网

Fortran 指向派生类型的指针的声明是否可以未定义?

Fortran 指向派生类型的指针的声明是否可以未定义?,fortran,gfortran,Fortran,Gfortran,我有一个小代码,声明了一个指向派生类型数组的指针,该数组有一个字段,该字段是另一个派生类型的可分配数组,该数组有一个实数变量作为字段。 使用gnu fortran(8.2),我可以为数组中的每个位置或作为向量获得不同的结果 使用英特尔fortran(2019.4)编译器成功 program test implicit none integer, parameter :: length = 2 real(8), dimension(length) :: a, b integer :: i typ

我有一个小代码,声明了一个指向派生类型数组的指针,该数组有一个字段,该字段是另一个派生类型的可分配数组,该数组有一个实数变量作为字段。 使用gnu fortran(8.2),我可以为数组中的每个位置或作为向量获得不同的结果

使用英特尔fortran(2019.4)编译器成功

program test
implicit none
integer, parameter :: length = 2
real(8), dimension(length) :: a, b
integer :: i

type point
   real(8) :: x
end type point

type stored
   type(point), dimension(:), allocatable :: np
end type stored

type(stored), dimension(:), pointer :: std=>null()


allocate(std(1))
allocate(std(1)%np(length))
std(1)%np(1)%x = 0.3d0
std(1)%np(2)%x = 0.3555d0

do i = 1, length
   write(*, "('std(1)%np(',i1,')%x = ',1e22.14)") i, std(1)%np(i)%x
end do
do i = 1, length
   write(*, "('std(1)%np(1:',i1,') = ',2e22.14)") i, std(1)%np(1:i)%x
end do
a = std(1)%np(1:2)%x
b = [std(1)%np(1)%x, std(1)%np(2)%x]
if (norm2(a - b) .gt. 1d-3) then
   write(*,*) 'failure'
else
   write(*, *) 'success'
end if
end program test

代码成功终止,但使用gfortran one在屏幕上获得“失败”和上面不一致的打印,使用英特尔编译器one在屏幕上获得“成功”和上面一致的打印。

我不清楚您的问题是什么,除非是标题。如果是,则不需要,指向派生类型的指针也可以。您的程序正确地将std分配为区段1数组,然后分配std(1)%np(2)。然后分配给两个np元素的x子组件。我觉得不错


有几件事可能会导致“失败”-您应该在调试器中运行gfortran代码,看看出了什么问题。

上面代码中出现的问题在下面的[链接]中得到了解决。

我看到您还将此发布在comp.lang.fortran上,在那里它被确认为gfortran错误。谢谢,Steve。当然,它已经作为gfortran bug打开了。它由gfortran开发人员处理。在gfortran中附加选项“-fsanize=address-g”可能很有用,因为它给出了源行的运行时错误(发生内存问题时,指向std(1)%np(1:2)%x行)。在我的机器上,使用gfortran-4.9或5(或使用allocatable代替“std”的指针)可以删除错误。