fortran 循环控制变量为实型时编译老有Warning如题,比如说有段代码如下program testimplicit nonereal s,xx=0.1do s=0.1,0.9,0.1x=s+1write(*,*)xend doend编译的话会出现如下编译提示do s=0.1,0.9,0.11Warning:Deleted feature:
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/07 21:39:41
fortran 循环控制变量为实型时编译老有Warning如题,比如说有段代码如下program testimplicit nonereal s,xx=0.1do s=0.1,0.9,0.1x=s+1write(*,*)xend doend编译的话会出现如下编译提示do s=0.1,0.9,0.11Warning:Deleted feature:
fortran 循环控制变量为实型时编译老有Warning
如题,比如说有段代码如下
program test
implicit none
real s,x
x=0.1
do s=0.1,0.9,0.1
x=s+1
write(*,*)x
end do
end
编译的话会出现如下编译提示
do s=0.1,0.9,0.1
1
Warning:Deleted feature:Loop variable at (1) must be integer
do.f95:5.6:
do s=0.1,0.9,0.1
1
Warning:Deleted feature:Start expression in DO loop at (1) must be integer
do.f95:5.10:
do s=0.1,0.9,0.1
1
Warning:Deleted feature:End expression in DO loop at (1) must be integer
do.f95:5.14:
do s=0.1,0.9,0.1
1
Warning:Deleted feature:Step expression in DO loop at (1) must be integer
但是会有可执行程序生成.
我想问下为什么会有警告提示,fortran不是支持非整型循环控制变量么?如果没有其他方法避免警告的话怎么加入编译选项使其不提示警告?
PS:本人使用的是编译器是GNU Fortran (Ubuntu 4.4.3-4ubuntu5) 4.4.3
fortran 循环控制变量为实型时编译老有Warning如题,比如说有段代码如下program testimplicit nonereal s,xx=0.1do s=0.1,0.9,0.1x=s+1write(*,*)xend doend编译的话会出现如下编译提示do s=0.1,0.9,0.11Warning:Deleted feature:
我用的也是gfortran,也碰到这种问题,所以我现在已经用整型来循环了.不过你如果要忽略警告,可以这样子,在编译时加上-std=legacy:
gfortran testloop.f90 -o testloop -std=legacy
不过我的是windows下,不知道你的版本行不行?
下面是手册的原话,关于-std=std
Specify the standard to which the program is expected to conform, which maybe one of ‘f95’, ‘f2003’, ‘gnu’, or ‘legacy’. The default value for std is ‘gnu’,which specifies a superset of the Fortran 95 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’ and ‘f2003’ values specify strict conformance to the Fortran 95 and Fortran 2003 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.