ToDo:
equivalence宣言された publicな module変数の参照であるが、 直管に反する動作をしている模様。
module tmacro_flags
implicit none
private
public tflag_get, tflag_set, tflag_reset
logical, public :: flags(3), rad, rfsw, radcod
equivalence (flags(1), rad)
equivalence (flags(2), rfsw)
equivalence (flags(3), radcod)
contains
logical function tflag_get()
implicit none
tflag_get = flags(2)
return
end function tflag_get
subroutine tflag_set()
implicit none
flags(2) = .true.
return
end subroutine tflag_set
subroutine tflag_reset()
implicit none
flags(2) = .false.
return
end subroutine tflag_reset
end module tmacro_flags
subroutine reset
use tmacro_flags, only: tflag_reset
logical exist
call tflag_reset()
end subroutine
subroutine set1
use tmacro_flags, only: tflag_set
logical exist
call tflag_set()
end subroutine
subroutine set2
use tmacro_flags, only: rfsw
rfsw = .true.
end subroutine
subroutine test0
use tmacro_flags, only: tflag_get
write(*,*) 'Test0: rfsw = ', tflag_get()
end subroutine
subroutine test1
use tmacro_flags, only: rfsw
write(*,*) 'Test1: rfsw = ', rfsw
end subroutine
subroutine test2
use tmacro_flags, only: flags, rfsw
write(*,*) 'Test2: rfsw = ', rfsw
end subroutine
implicit none
call reset()
call set1()
call test0()
call test1()
call test2()
call reset()
call set2()
call test0()
call test1()
call test2()
end
なぜかflags(2)のequivalenceであるrfswの参照結果が、flagsシンボルを 取り込むかどうかで変化している(gfortran 4.6.0 2010/07/03)
Test0: rfsw = T Test1: rfsw = F Test2: rfsw = T Test0: rfsw = F Test1: rfsw = T Test2: rfsw = F
しかも、equivalence文の順序を入れ替えて rfswを最後にすると
Test0: rfsw = T Test1: rfsw = T Test2: rfsw = T Test0: rfsw = T Test1: rfsw = T Test2: rfsw = T
となり、期待通りに動く。 なんとなく、gfortranのバグのように思えるのだが...
ようなので、gfortranの実装バグの可能性が高い...
カテゴリー: Admin | Emacs | EPICS | Fortran | FreeBSD | GCC | hgsubversion | IPv6 | KEKB | LHC | Lisp | LLVM | MADX | Ryzen | SAD | samba | tDiary | unix | WWW | YaSAI | お仕事 | イベント | 出張 | 宴会 | 数学 | 艦これ | 買いもの | 追記 | 雑記