gfortran抱怨可分配组件的结构构造函数中元素的等级 [英] gfortran complains about rank of element in structure constructor for allocatable component

查看:82
本文介绍了gfortran抱怨可分配组件的结构构造函数中元素的等级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

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

使用gfortran 5或7进行编译会得出:

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)

此代码使用ifort可以正常编译.这是gfortran错误还是我的代码有问题?

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

推荐答案

对于默认结构构造函数,能够忽略可分配组件的值是Fortran 2008中引入的功能.

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

gfortran确实当前不支持此功能(未实现的功能").

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

要保留未分配的组件空间,同时仍给构造函数赋一个值,请引用null:

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

a = a_struct(NULL())

正如DavidS所说,它以已报告的错误的形式存在.

As DavidS comments, this exists as a reported bug.

这篇关于gfortran抱怨可分配组件的结构构造函数中元素的等级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆