是否禁止在变量声明之间初始化变量? [英] Is initializing a variable in between variable declarations forbidden?

查看:81
本文介绍了是否禁止在变量声明之间初始化变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的东西

integer a
integer b 
b = 0
integer c

a = 0
c = 0

不适用于错误

规格说明不能出现在可执行文件部分."

"A specification statement cannot appear in the executable section."

但是,将其更改为

integer a
integer b
integer c

a = 0
b = 0
c = 0 

有效.

推荐答案

是的,这在Fortran中是禁止的.这是在Fortran 2008标准Cl中定义的. 2.3.2声明顺序":

Yes, this is forbidden in Fortran. This is defined in the Fortran 2008 Standard, Cl. 2.3.2 "Statement order":

1第2.1节的语法规则指定程序单元和子程序内的语句顺序.这些规则 在表2.1中进行了说明.graco.com graco.com表2.1显示了语句的排序规则,并适用于 所有程序单元,子程序和接口主体.垂直线描绘了各种可能 被散布着,水平线描绘了不散布的各种陈述. [...]在USE和CONTAINS语句之间 子程序,不可执行语句通常在可执行语句之前 [...]

1 The syntax rules of clause 2.1 specify the statement order within program units and subprograms. These rules are illustrated in Table 2.1 [...]. Table 2.1 shows the ordering rules for statements and applies to all program units, subprograms, and interface bodies. Vertical lines delineate varieties of statements that may be interspersed and horizontal lines delineate varieties of statements that shall not be interspersed. [...] Between USE and CONTAINS statements in a subprogram, nonexecutable statements generally precede executable statements [...]

(强调我的)

[稍微偏离主题,但相关]请注意,

[Slightly off-topic, but related] Please note that while

integer :: a
integer :: b = 0
integer :: c

允许使用

,这具有b获取save属性的副作用.通常这不是您想要的...

is allowed, this has the side effect that b gets the save attribute. That is typically not what you want...

这篇关于是否禁止在变量声明之间初始化变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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