lookbook 发表于 2019-8-16 21:28:22

有关gfortran初始值的设定的问题

遇到一个问题,请教各位大佬
module m_haha
    implicit none
    real :: nan_4
end

program main
    use m_haha
    implicit none
    real :: a

    print*,nan_4,a
end program
编译方式:
gfortran -finit-real=nan -c m_haha.f90
gfortran -finit-real=nan -c main.f90
gfortran -finit-real=nan *.o

结果:
0.0000 nan

很迷。。。


fcode 发表于 2019-8-18 08:52:04

       -finit-local-zero
       -finit-integer=n
       -finit-real=<zero|inf|-inf|nan>
       -finit-logical=<true|false>
       -finit-character=n

The -finit-local-zero option instructs the compiler to initialize local "INTEGER",
         "REAL", and "COMPLEX" variables to zero, "LOGICAL" variables to false, and "CHARACTER"
         variables to a string of null bytes.Finer-grained initialization options are
         provided by the -finit-integer=n, -finit-real=<zero|inf|-inf|nan> (which also
         initializes the real and imaginary parts of local "COMPLEX" variables),

lookbook 发表于 2019-8-19 11:09:42

fcode 发表于 2019-8-18 08:52
-finit-local-zero
       -finit-integer=n
       -finit-real=


{:4_90:}也就是说,module中定义的变量不是local的?

fcode 发表于 2019-8-19 15:10:16

不是,只有子程序(函数)的局部变量,主程序的变量,才叫“local variables”

lookbook 发表于 2019-8-19 18:55:30

fcode 发表于 2019-8-19 15:10
不是,只有子程序(函数)的局部变量,主程序的变量,才叫“local variables” ...

多谢绝地答疑

chiangtp 发表于 2020-8-10 22:27:16

1. (nan_4, a) = (0.0, 0.0), (nan, nan), (0.0, nan), (nan, 0.0) or (莫名其妙的數字)
是 compiler, compile-time-switches dependent的
據此評論編譯器沒有意義, 就科學計算而言, 是程式員的錯(未定義就使用)

2. 我認為MODULE的变量也是"local variables", 請參考:



页: [1]
查看完整版本: 有关gfortran初始值的设定的问题