Fortran读取语句不提供编译错误 [英] Fortran read statement gives no compilation error

查看:357
本文介绍了Fortran读取语句不提供编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 程序测试
字符(len)为什么gfortran在读取语句时不显示任何编译错误? = 2):: x
read x
end program


解决方案

编译器不会发出错误,因为所有单独的行都是有效的,并且错误只能在运行时检测到。你可能会认为 read 会从某处读取数据并将其存储在 x 中,但这不是发生。声明

 阅读x 

符合Fortran 2008标准中的R910(cl 9.6.1)。具体而言, read-stmt 的一种可能性是:


阅读格式 input-item-list ]


符合读取x ,将 x 解释为格式。你可以通过运行你的程序来确认它,这会产生运行时错误:

$ p $ 在文件read.f90的第3行(单元= 5,file ='stdin')
Fortran运行时错误:格式为
的初始左括号丢失


Why is gfortran not showing any compilation error for the read statement here?

program test
    character(len=2) :: x
    read x
end program

解决方案

The compiler does not issue an error because all individual lines are valid and the error can only be detected at runtime. You may think that read is going to read data from somewhere and store it in x, but that is not what is happening. The statement

read x

matches R910 in the Fortran 2008 standard (cl 9.6.1). Specifically, one possibility of read-stmt is:

READ format [, input-item-list]

which will match read x, interpreting x as a format. You can confirm this by running your program, which produces the runtime error:

At line 3 of file read.f90 (unit = 5, file = 'stdin')
Fortran runtime error: Missing initial left parenthesis in format

这篇关于Fortran读取语句不提供编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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