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

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

问题描述

请看下面的例子

 program test

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

end

返回如下错误:

(1) 处的数组构造函数中的不同字符长度 (10/12)

Different CHARACTER lengths (10/12) in array constructor at (1)

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.

另外,改用

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天全站免登陆