我有以下Fortran 95代码:
import os
import sys
f = open(os.devnull, 'w')
temp = sys.stdout
sys.stdout = f
# print is disabled here
sys.stdout = temp
# print works again!
现在我用
编译它MODULE ISSUE
IMPLICIT NONE
CONTAINS
SUBROUTINE PROBLEM(A)
IMPLICIT NONE
DOUBLE PRECISION, DIMENSION(:,:), INTENT(INOUT) :: A
INTEGER :: i, n
n = SIZE(A, 2)
DO i = 1, n
PRINT *, A(i, 1:n)
ENDDO
END SUBROUTINE PROBLEM
END MODULE ISSUE
PROGRAM TEST
USE ISSUE
IMPLICIT NONE
DOUBLE PRECISION, DIMENSION(5, 5) :: A
A = TRANSPOSE(RESHAPE((/ 1, 2, 3, 4, 5, &
6, 7, 8, 9, 0, &
1, 2, 3, 4, 5, &
6, 7, 8, 9, 0, &
1, 2, 3, 4, 5/), SHAPE(A)))
CALL PROBLEM(A)
END PROGRAM TEST
然后我使用GDB 7.7.1运行程序,并将断点设置为第11行(gfortran -g -O0 problem.f95 -o problem
)。之后,我打印矩阵A的第一个元素。我得到的输出是:
DO i = 1, n
我希望输出 1 ,但gdb会打印 6.9533558074105031e-310 。请注意,子例程(gdb) break 11
Breakpoint 1 at 0x4008c5: file problem.f95, line 11.
(gdb) run
Starting program: /path_to_problem_folder/problem
Breakpoint 1, issue::problem (a=...) at problem.f95:11
warning: Source file is more recent than executable.
11 DO i = 1, n
(gdb) p A(1, 1)
$1 = 6.9533558074105031e-310
正确打印所有值。
为什么会发生这种情况?如何使用GDB正确打印值PROBLEM
?
答案 0 :(得分:0)
我将我的GDB版本从7.7.1更新为7.11.1,问题就消失了。