Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compilation 在编译或运行时检测错误的别名_Compilation_Fortran - Fatal编程技术网

Compilation 在编译或运行时检测错误的别名

Compilation 在编译或运行时检测错误的别名,compilation,fortran,Compilation,Fortran,是否有某种工具(或编译标志)可以在编译期间或运行时检测Fortran代码中有问题的别名?我看到gfortran有-Waliasing,但它只检测最严重的情况(例如调用which(x,x),而不是调用which(x(1),x(1)))。英特尔的ifort有-fno别名,但显然这只是意味着编译后的代码可能会给出不同的结果。考虑这样的代码: program main implicit none real :: x(100) integer :: i do i=1,size(x) x(i) = i

是否有某种工具(或编译标志)可以在编译期间或运行时检测Fortran代码中有问题的别名?我看到gfortran有
-Waliasing
,但它只检测最严重的情况(例如
调用which(x,x)
,而不是
调用which(x(1),x(1))
)。英特尔的ifort有
-fno别名
,但显然这只是意味着编译后的代码可能会给出不同的结果。考虑这样的代码:

program main
implicit none
real :: x(100)
integer :: i

do i=1,size(x)
  x(i) = i
end do

call sub(100,x(1:100),x(1:100))

contains

subroutine sub(n,a,b)
implicit none
integer, intent(in) :: n
real, intent(in) :: a(n)
real, intent(out) :: b(n)

b(:) = a(:)

end subroutine sub

end program main

我没有收到任何类型的警告(编译或运行),因为对两个伪参数(
a
b
)使用相同的内存地址(
x(1:100)
),其中一个参数被修改,据我所知,这是标准所禁止的。

我想你的问题是,它不会抛出警告,你提供了
x(1)
作为输入和输出变量?或者我误解了你的问题,而实际问题是输入参数的长度是1而不是100(因为
size(x)
将产生)?@IanBush可以在F2018 15.5.2.13中找到是否需要诊断别名冲突的答案(否)。一般来说,这种检测被称为“有点棘手”,因此最好避免依靠检测所有错误案例而不进行虚假报告。@IanBush,fwiw,使用
nagfor-C=all-f2008main.f90
(使用
NAG Fortran编译器6.1版(Tozai)Build 6116
)编译结果在我的系统上没有编译或运行时消息。不要使用NAG进行过多的探索:“当检测到对伪参数的赋值影响另一个伪参数时,-C=alias选项将产生运行时错误。在本版本中,仅对标量伪参数检测到此错误。”为了完整性:不可能在“编译时”完成别名冲突检查。编写一个程序非常容易,在这个程序中,在运行时,对别名限制的违反或一致性取决于用户输入。