【问题标题】:symbol has no Implicit type符号没有隐式类型
【发布时间】:2015-09-15 13:01:42
【问题描述】:

我正在通过 fortran 90 运行此代码

   Program Projectile
! This Program Calculates the Velocity and Height of a
! Projectile
! Given its Initial Height, Initial Velocity and Constant
! Acceleration.
Implicit None
Real :: Initial_Hight, Height, Initial_Velocity, Velocity, &
Time, Acceleration = -9.807
! Obtain Values for Initial Height, Initial Velocity and
! Time
Print*, "Enter the Initial Height and Velocity:"
Read*, Initial_Height, Initial_Velocity
Print*, "Enter Time at Which to Calculate Height and &
Velocity:"
Read*, Time
! Calculate the Height and Velocity
Height = 0.5 * Acceleration * Time ** 2 + Initial_Velocity &
* Time + Initial_Height
Velocity = Acceleration * Time + Initial_Velocity
! Display Velocity and Height
Print*, "At Time", Time, "The Vertical Velocity is", Velocity
Print*, "and the Height is", Height
End Program Projectile

但我经常收到此错误:错误符号“initial_height”没有隐式类型,在删除隐式空行后,我不能使用实数,因为实数会导致另一个错误,你能帮帮我吗?

【问题讨论】:

    标签: fortran


    【解决方案1】:

    你有两个问题。

    正如 Gilles 指出的那样,您现有的代码中有错字。

    您的第二个问题是您不了解 FORTRAN 隐式类型规则。除非另有声明,否则名称以 I、J、K、L、M 或 N 开头的变量是隐式 INTEGER。除非另有声明,否则所有其他变量都是隐式 REAL。

    INITIAL_HEIGHT 是隐含的 INTEGER,除非你声明它为 REAL,但你没有这样做。您已将 INITIAL_HIGHT 声明为 REAL,但未声明 INITIAL_HEIGHT。通常,它会被隐式地设为 INTEGER,这会导致对 barf 的真正赋值。因为您通过 IMPLICIT NONE 完全禁用了隐式类型,所以 INITIAL_HEIGHT 没有类型。

    这就是编译器试图告诉你的。

    【讨论】:

    • 这非常令人困惑。这真的只是一个错字。
    • @VladimirF,你说得对,他的基本问题是错字。但是,为了解释编译器错误信息,他有必要了解 FORTRAN 隐式类型规则。
    • 解释为什么比修复本身重要得多。 +1
    【解决方案2】:

    您只是在这里的代码中有错字:

    Real :: Initial_Hight, Height, Initial_Velocity, Velocity, &
      Time, Acceleration = -9.807
    

    应该读什么

    Real :: Initial_Height, Height, Initial_Velocity, Velocity, &
      Time, Acceleration = -9.807
    

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多