在GNU Fortran编译器的文档中,对于特定的内部函数,有一个标准。例如,CPU_TIME是一个内在的过程,它表明标准是Fortran 95及更高版本。我的问题是关于这件事的意义。
我理解Fortran标准就像一组规则,您的代码将被定义为符合标准的( Fortran 77,90,95,2003或2008)。这是否意味着CPU_TIME只能与Fortran 95+一起使用?实际上,我已经知道答案了,我可以在一个具有.f扩展名的Fortran 77文件中使用.f,而不用编译器抱怨,使用Gfortran版本> 5编译。这是因为编译器能够处理代码中遇到的任何标准吗?我知道-std标志,但我如何确定,例如,Fortran 77代码只使用Fortran 77的内部过程?
发布于 2016-09-15 19:37:37
简单地说,你不能用gnu编译器区分f95下面的标准。在f95和更高版本中,您可以使用选项-std强制编译器将上述标准特性视为错误。
较长的答覆:
gnu编译器文档说:
-std=std指定程序应该遵循的标准,这可能是“f95”、“f 2003”、“f 2008”、“gnu”或“旧版”之一。std的默认值是“GNU”,它指定了Fortran 95标准的超集,其中包括GNU Fortran支持的所有扩展,但对于不建议在新代码中使用的过时扩展,将发出警告。“遗留”值是等价的,但没有对过时的扩展发出警告,并且可能对旧的非标准程序有用。“f95”、“f2003”和“f2008”值分别指定严格符合Fortran 95、Fortran 2003和Fortran 2008标准;超出相关语言标准的所有扩展都会出现错误,并对以后标准中允许但过时的Fortran 77特性发出警告。“-std=f2008ts”允许Fortran 2008标准,包括关于Fortran与C的进一步互操作性的技术规范( TS ) 29113和关于Fortran中其他并行特性的TS 18508。
- `-std=f95` will consider features above f95 as errors
- `-std=f2003` will consider features above f2003 as errors
- `-std=f2008` will consider features above f2008 as errors
- etc.您可能需要与其他编译器进行检查。
容易验证:编译下面的程序(由Fortran wiki提供)和选项-std=f95,看看会发生什么。
module class_Circle
implicit none
private
real :: pi = 3.1415926535897931d0 ! Class-wide private constant
type, public :: Circle
real :: radius
contains
procedure :: area => circle_area
procedure :: print => circle_print
end type Circle
contains
function circle_area(this) result(area)
class(Circle), intent(in) :: this
real :: area
area = pi * this%radius**2
end function circle_area
subroutine circle_print(this)
class(Circle), intent(in) :: this
real :: area
area = this%area() ! Call the type-bound function
print *, 'Circle: r = ', this%radius, ' area = ', area
end subroutine circle_print
end module class_Circle
program circle_test
use class_Circle
implicit none
type(Circle) :: c ! Declare a variable of type Circle.
c = Circle(1.5) ! Use the implicit constructor, radius = 1.5.
call c%print ! Call the type-bound subroutine
end program circle_testhttps://stackoverflow.com/questions/39517221
复制相似问题