gfortran不允许具有不同组件长度的字符数组 [英] gfortran does not allow character arrays with varying component lengths

查看:242
本文介绍了gfortran不允许具有不同组件长度的字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

见下面的例子:

See the example below

 program test

 character(10),dimension(5):: models = (/"feddes.swp", "jarvis89.swp", "jarvis10.swp" ,   "pem.swp", "van.swp"/)

end

返回以下错误:

The following error is returned:


ifort编译器没有错误。为什么它会发生在gfortran上,并且有什么办法可以绕过这个问题?

There is no error with ifort compiler. Why does it happen with gfortran and is there any way to circumvent this problem?

推荐答案

构造函数中有一些长度为12,因此使用长度为12可能会更好。

You have some lengths 12 in the constructor, so it may be better to use length 12.

另外,使用

Also, use instead

character(len=12), dimension(5) :: models = [character(len=12) :: "feddes.swp", &
                "jarvis89.swp", "jarvis10.swp", "pem.swp", "van.swp"]

如果您有编译器支持,可能更好,是

Possibly even better, if you have compiler support, is

character(len=*), dimension(*) :: ...

这篇关于gfortran不允许具有不同组件长度的字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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