I’m modernizing odrpack. As part of the conversion process, I’ve added intent(in/out)
to all procedure arguments. Not being my code, I’ve struggled quite a bit trying to figure out what should be out
or inout
. Inevitably, I mislabeled a few arguments as just out
, which led to hard-find problems. Unbelievable as it may seem (at least for me), the buggy code worked just fine in linux+gcc+debug/release and windows+gcc+debug, but failed in windows+gcc+release.
Anyway, this got me wondering how to detect this type of issues. IMO, the following code has an obvious problem in the first executable statement (y = x
), but I can’t seem to make the compiler tell me about it.
How do you address these issues?
subroutine foo(x, y)
implicit none
integer, intent(out) :: x
integer, intent(out) :: y
integer :: i
real :: a, b, c
y = x
i = i + 1
a = a + 1.
b = c
end subroutine
PS C:\Code\odrpack95\src> gfortran -c test.f90 -Wuninitialized
test.f90:8:13:
8 | i = i + 1
| ^
Warning: 'i' is used uninitialized [-Wuninitialized]
test.f90:5:16:
5 | integer :: i
| ^
note: 'i' was declared here
test.f90:9:14:
9 | a = a + 1.
| ^
Warning: 'a' is used uninitialized [-Wuninitialized]
test.f90:6:13:
6 | real :: a, b, c
| ^
note: 'a' was declared here
test.f90:10:9:
10 | b = c
| ^
Warning: 'c' is used uninitialized [-Wuninitialized]
test.f90:6:19:
6 | real :: a, b, c
| ^
note: 'c' was declared here