1
此gcc Fortran編譯警告的補救措施是什麼?與Fortran子模塊和gcc compliation標誌混淆-Wuse-without-only
USE statement at (1) has no ONLY qualifier
在gcc 6.0,6.1,6.2和7.0中使用子模塊時發生警告。
的完整編譯序列和警告:
$ gfortran -c -Wuse-without-only -o mod_module.o mod_module.f08
$ gfortran -c -Wuse-without-only -o mod_module_sub.o mod_module_sub.f08
mod_module_sub.f08:1:19:
submodule (mModule) mSubModule
1
Warning: USE statement at (1) has no ONLY qualifier [-Wuse-without-only]
$ gfortran -c -Wuse-without-only -o demonstration.o demonstration.f08
$ gfortran -o demonstration demonstration.o mod_module.o mod_module_sub.o
$ ./demonstration
this + that = 3.00000000
expected value is 3
主程序(demonstration.f08):
program demonstration
use mModule, only : myType
implicit none
type (myType) :: example
example % this = 1.0
example % that = 2.0
call example % adder ()
write (*, *) 'this + that = ', example % other
write (*, *) 'expected value is 3'
stop
end program demonstration
模塊(mod_module.f08):
module mModule
implicit none
type :: myType
real :: this, that, other
contains
private
procedure, public :: adder => adder_sub
end type myType
private :: adder_sub
interface
module subroutine adder_sub (me)
class (myType), target :: me
end subroutine adder_sub
end interface
end module mModule
子模塊(mod_module_sub .f08):
submodule (mModule) mSubModule ! <=== problematic statement
implicit none
contains
module subroutine adder_sub (me)
class (myType), target :: me
me % other = me % this + me % that
end subroutine adder_sub
end submodule mSubModule
也就是說,指定子模塊的正確方法是什麼?標記-Wuse-without-only
對編譯較長代碼至關重要。
我的任何代碼都不會在沒有警告的情況下通過該選項。 –