fortran - 在同一个 ASSOCIATE 构造中引用另一个关联实体中的关联名称
问题描述
如果我的标准语不是很好,我很抱歉,但是以下 Fortran 2008 不是合法的吗?
program test
implicit none
associate ( a => 6, b => 2*a )
print*, b
end associate
end program
我的编译器抱怨a
没有被声明并且没有隐式类型。
编辑:
我认为选择器只能是表达式或变量,而不能是关联名称或涉及其中的表达式。是这样吗?
解决方案
这是一个(嵌套)版本,可以满足您的需求,而您的版本不符合 Fortran 标准,
program test
implicit none
integer a ! note that a has be defined here because it is used as a VARIABLE in the association list below
associate ( a => 6, b => 2*a )
print*, b
end associate
associate ( a => 6 )
associate ( b => 2*a )
print*, b
end associate
end associate
end program
这是Gfortran编译的程序的输出,
$gfortran -std=gnu main.f90 -o main
$main
483386368
12
根据 Fortran 标准,该构造允许在块的持续时间内将associate
名称与变量或表达式的值相关联。这是一般语法,
[ construct-name: ] associate ( association-list )
block
end associate [ construct-name ]
因此,我认为您对该associate
构造的使用不符合标准。基本上,在您的代码中,编译器假定关联列表a
中的b => 2*a
in 指的a
是已在关联构造和列表之外定义的变量(与关联列表中定义的名称相反a
)。
正如@HighPerformanceMark 所建议的那样,associate
像上面的示例这样的嵌套结构可以实现您想要的目标。
推荐阅读
- linux - 用于打印具有最长执行时间的 recordId 的 Shell 脚本
- validation - 就返回 HTTP 状态代码而言,无效的表单数据提交是“错误”还是“正常”?
- post - 使用 curl 与 python 请求的不同结果
- c# - Xamarin Android:存档-“未安装应用程序。包似乎已损坏”
- reactjs - 如何使用 React 函数组件获取组件的位置
- python - 数据映射/转换
- firebase - 有没有办法检测 Firestore 是否因为客户端位于代理后面而无法工作?
- javascript - 如何找到一个范围内的最小数字,并在谷歌表格中将该数字增加 1?
- java - 如何使用 JNA 处理 Java 内部内存访问
- kubernetes - 如何配置 Keycloak Helm Chart