我有一个 Fortran 程序,我试图将一个字符串传递给一个子程序。我下面示例中的代码按预期运行,本身没有错误。但是,编译后: f95 -g test.f95
并且在使用 GDB 跟踪代码时出现问题。
program test
character(len=4):: my_string="asdf"
call test_routine(my_string)
contains
subroutine test_routine(asdf)
character(len=*) :: asdf
print*, len(asdf)
print*, asdf
return
end subroutine test_routine
end program test
Run Code Online (Sandbox Code Playgroud)
在两个打印*之间的第 12 行设置断点时,语句在 GDB 中运行代码时得到以下输出
Starting program: /home/user/folder/a.out
4
Breakpoint 1, test_routine (asdf=<error reading variable: value requires 4158328176 bytes, which is more than max-value-size>, _asdf=4) at test.f95:13
13 print*, asdf
Run Code Online (Sandbox Code Playgroud)
如输出所示,Fortran 将字符串的 len() 打印为 '4',但 GDB 将其视为 ~4GiB
这是什么原因造成的?
GDB 版本:GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Fortran (gcc) 版本:gcc …