gpt4 book ai didi

initialization - Fortran:错误 #6562:数据初始化表达式对此对象无效

转载 作者:行者123 更新时间:2023-12-04 11:23:54 29 4
gpt4 key购买 nike

我试图将 Fortran 子例程中的本地逻辑数组初始化为 false,但出现错误:

error #6562: A data initialization-expr is not valid for this object.



这里是我的报关表:
  integer                      , intent(in)    :: nLOW 
integer , intent(in) :: nUP
logical , dimension(nLOW:nUP) :: leastSQUARE = .false.

如果我使用,我会得到同样的错误:
  integer                                      :: I
integer , intent(in) :: nLOW
integer , intent(in) :: nUP
logical , dimension(nLOW:nUP) :: leastSQUARE = (/ (.false., I = nLOW:nUP) /)

如果我写:
  integer                      , intent(in)    :: nLOW 
integer , intent(in) :: nUP
logical , dimension(1:100) :: leastSQUARE = .false.

子程序编译时错误为零。知道为什么会这样吗?我显然需要 leastSQUARE带尺寸 nLOW:nUP ,所以后者不是解决方法。

最佳答案

我相信语言标准禁止产生错误的构造,特别是(在 Fortran 2008 版本中)R503 上的 C506。该约束指出

An initialization shall not appear if object-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable variable, or an automatic object.


leastSQUARE就是这样一个自动对象,其边界仅在运行时才知道。您必须将其与其声明分开初始化。

要清楚(感谢@IanH),您必须执行赋值语句来为您的自动对象提供初始值。我在上一段中使用的动词初始化不是 Fortran 标准标准。

关于initialization - Fortran:错误 #6562:数据初始化表达式对此对象无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25444200/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com