我知道gfortran可以编译f90或f95吗?它如何知道它正在编译哪一个?它还可以编译f77代码吗? ubuntu 是否已经有 fortran 编译器,还是我需要下载 gfortran?
最佳答案
gfortran 可以从文件扩展名中猜测某些内容;如果文件的扩展名为 .f、.f90、f95、.f03 或 .f08,它将采用具有适当标准的固定 (.f) 或自由格式。但是您可以使用选项 -std=f2003 强制它编译(例如)fortran2003 代码。例如,来自 documentation ,
-std=std
Specify the standard to which the program is expected to conform, which may be one of
f95
,f2003
,f2008
,f2018
,gnu
, orlegacy
. The default value for std isgnu
, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran, although warnings will be given for obsolete extensions not recommended for use in new code. Thelegacy
value is equivalent but without the warnings for obsolete extensions, and may be useful for old non-standard programs. Thef95
,f2003
,f2008
, andf2018
values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards.-std=f2008ts
allows the Fortran 2008 standard including the additions of the Technical Specification (TS) 29113 on Further Interoperability of Fortran with C and TS 18508 on Additional Parallel Features in Fortran.
请注意,除了少数异常(exception),fortran 标准是高度向后兼容的,因此很多“好的”、符合标准的 fortran-77 代码也是有效的 fortran 2003 代码。主要问题是 80 年代及更早版本的许多 Fortran 代码既不“好”也不符合标准。
关于fortran - gfortran 如何判断我正在编译 f90 还是 f95 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10884260/