fortran - gfortran 如何判断我正在编译 f90 还是 f95 代码?

标签 fortran fortran90 gfortran fortran77

我知道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, or legacy. The default value for std is gnu, 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. The legacy value is equivalent but without the warnings for obsolete extensions, and may be useful for old non-standard programs. The f95, f2003, f2008, and f2018 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/

相关文章:

fortran - 如何知道 Fortran 中带有尾随空格的用户输入的长度?

audio - 在 Fortran 90/95 中生成声音/蜂鸣声

python - 将 SciPy 编译为 Android - 是否已完成,关于如何将 FORTRAN 代码编译为 Android Arm 的任何帮助

fortran - MPI 散射中的尺寸标注

c - 通过 ISO_C_BINDING 传递 Fortran 数组

fortran - Fortran 中的嵌套名单

save - FORTRAN 子程序何时保存数据,何时不保存?

c++ - 从 FORTRAN 代码调用的 C++ 函数调用 C++ 函数

linker - fortran 中的多重定义链接错误(ifort - gfortran)

gcc - gfortran:尝试执行 'f951' 时出错:execvp:没有这样的文件或目录