gfortran complains about rank of element in structure constructor for allocatable component

女生的网名这么多〃 提交于 2020-07-03 07:41:29

问题


Consider the following code:

subroutine tao_show_this ()
implicit none

type b_struct   
integer, pointer :: good_user => null()
end type

type a_struct   
 type (b_struct), allocatable :: value_ptr(:)
end type

type (a_struct) a
a = a_struct()

end subroutine

Compiling with gfortran 5 or 7 gives:

gfortran -c test.f90
test.f90:4:13:

 type b_struct
             1
Error: The rank of the element in the structure constructor at (1) does not match that of the component (0/1)

This code compiles fine with ifort. Is this a gfortran bug or is there something wrong with my code?


回答1:


For a default structure constructor, being able to omit the value for an allocatable component is a feature introduced in Fortran 2008.

gfortran does not currently support this feature ("Unimplemented features").

To leave the component not allocated while still giving a value to the constructor one references null:

a = a_struct(NULL())

As DavidS comments, this exists as a reported bug.



来源:https://stackoverflow.com/questions/52712245/gfortran-complains-about-rank-of-element-in-structure-constructor-for-allocatabl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!