Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler errors &引用;“不可分类声明”;at if语句_Compiler Errors_Fortran - Fatal编程技术网

Compiler errors &引用;“不可分类声明”;at if语句

Compiler errors &引用;“不可分类声明”;at if语句,compiler-errors,fortran,Compiler Errors,Fortran,下面是我的代码中一个函数的MWE,它在编译时会产生两个错误: function foo (a) implicit none real, intent(in)::a real::foo if -1.0 < 0.0 then write(*,*) "hi" end if foo = a end function foo 函数foo(a) 隐式无 真实的,真实的意图 雷亚尔:福 如果-1.0

下面是我的代码中一个函数的MWE,它在编译时会产生两个错误:

  function foo (a)

    implicit none
    real,  intent(in)::a
    real::foo

    if -1.0 < 0.0 then
       write(*,*) "hi"
    end if

    foo = a 

  end function foo
函数foo(a) 隐式无 真实的,真实的意图 雷亚尔:福 如果-1.0<0.0,则 写(*,*)“嗨” 如果结束 foo=a 端函数foo 我在编译时遇到的错误有:

frag.f90:7063.8:
        if -1.0 < 0.0 then
        1
Error: Unclassifiable statement at (1)
frag.f90:7065.11:

        end if
           1
Error: Expecting END FUNCTION statement at (1)
框架f90:7063.8:
如果-1.0<0.0,则
1.
错误:位于(1)的不可分类语句
框架f90:7065.11:
如果结束
1.
错误:在(1)处应为结束函数语句
我不明白为什么我在
if
语句中得到一个不可分类的语句。我相信第二个错误与第一个错误有关(如果没有
if
语句,则无需关闭它),因此如果第一个错误得到修复,第二个错误也应该得到修复


我正在使用
gfortran
进行编译

您需要将逻辑表达式放在括号中:

if (-1.0 < 0.0) then

您需要将逻辑表达式放在括号中:

if (-1.0 < 0.0) then

Python搞坏了我。Python搞坏了我。当我教学时,我总是要求学生在条件周围添加括号,即使编程语言没有强加条件。它有利于可读性和调试,在fortran中确实是强制性的。当我教学时,我总是要求学生在条件周围添加括号,即使编程语言没有强制要求。它有利于可读性和调试,在fortran中确实是必需的。