Pointers 在gfortran中传递过程指针会导致segfault

Pointers 在gfortran中传递过程指针会导致segfault,pointers,segmentation-fault,fortran,gfortran,Pointers,Segmentation Fault,Fortran,Gfortran,我有一个过程指针,我需要向下传递一些函数,当使用gfortran而不是ifort编译时,它会崩溃。下面是一个演示该问题的简单示例: module mod1 abstract interface function f(x) double precision f double precision, intent(in) :: x end function f end interface contain

我有一个过程指针,我需要向下传递一些函数,当使用gfortran而不是ifort编译时,它会崩溃。下面是一个演示该问题的简单示例:

module mod1 abstract interface function f(x) double precision f double precision, intent(in) :: x end function f end interface contains subroutine printme(g) procedure(f), pointer, intent(in) :: g write(*,*) g(1d0), g(2d0), g(3d0) end subroutine printme subroutine printme2(g) procedure(f), pointer, intent(in) :: g call printme(g) end subroutine printme2 end module mod1 program test use mod1 procedure(f), pointer :: pg pg => g call printme2(pg) contains function g(x) double precision g double precision, intent(in) :: x g = x**2 return end function g end program test 显然,在我的程序中,我的printme2版本做的不仅仅是这些,但是你明白了。它多次调用另一个例程,每次都传递过程指针。现在,使用“英特尔编译器”,这项功能可以正常工作:

$ ifort segfault.f90 && ./a.out 1.00000000000000 4.00000000000000 9.00000000000000 但是,对于gfortran v4.4.5-8:

$ gfortran segfault.f90 && ./a.out Segmentation fault 请注意,如果我在测试程序中用printme替换printme2,它就会工作。
为什么会发生这种情况?我做错了什么以及如何纠正错误?

我没有GCC 4.4.5,但您的代码可以在gfortran 4.5.3、4.6.1和4.7.0中编译并正常工作,而在4.3.4中根本无法编译。我想说您遇到了一个bug或是在4.4.5中没有正确实现的东西。您可以查看汇编输出,但最好升级编译器。好的,我会要求我们的管理员升级。感谢您的测试!请注意,允许内部过程作为过程指针分配的过程目标是Fortran 2008标准的一项功能。我还测试了Gfortran 4.6.3,这是一个稳定的版本。我没有GCC 4.4.5,但您的代码可以编译并与Gfortran 4.5.3配合使用,4.6.1和4.7.0,并且根本不使用4.3.4进行编译。我想说您遇到了一个bug或是在4.4.5中没有正确实现的东西。您可以查看汇编输出,但最好升级编译器。好的,我会要求我们的管理员升级。感谢您的测试!请注意,允许内部过程作为过程指针分配的过程目标是Fortran 2008标准的一项功能。我也测试过,它在Gfortran 4.6.3这一稳定版本中运行良好。