How to make gfortran give a warning for reading variables declared as intent(out) without initializing it first?

Peng Yu pengyu.ut@gmail.com
Sun Jun 14 01:24:00 GMT 2015


Hi,

The following code shows that even "b" is declared as "real(dp),
intent(out)" in bar. It still can get the value 2 defined in the main
program.

I'd think that the gfortran should have warned the user that "b" is
used without being first set in "bar". Is this feature available in
gfortran? Thanks.

$ cat main.f90
program main
  integer, parameter :: dp=kind(1.0d0)
  real(dp) a, b
  a = 1
  b = 2
  call bar(a, b)
  print *, a, b
end program

subroutine bar (a, b)
  integer, parameter :: dp=kind(1.0d0)
  real(dp), intent(in) :: a
  real(dp), intent(out) :: b
  print *, b
  b = a
end subroutine

-- 
Regards,
Peng



More information about the Gcc-help mailing list