From Newsgroup: comp.lang.fortran
Lynn McGuire <
lynnmcguire5@gmail.com> schrieb:
"Mistakes in Fortran 90 Programs That Might Surprise You"
https://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
Oh yeah, I have seen several of these.
Nice list.
gfortran catches this one:
program main
real, dimension(5) :: x
x = 0.
! THIS IS WRONG
call incb(x)
print *, x
end program main
subroutine incb(a)
! this is a fortran90 style subroutine
real, dimension(:) :: a
a = a + 1.
end subroutine incb
$ gfortran x.f90
x.f90:6:15:
6 | call incb(x)
| 1
Error: Explicit interface required for 'incb' at (1): assumed-shape argument
but only within the same file. Same for this. The error message
could be better, but at least it points to the problem:
$ cat y.f90
program main
real, dimension(5) :: x
! interface to Fortran 77 style routine
interface
subroutine inca(a,n)
integer :: n
! THIS IS THE WRONG WAY
real, dimension(:) :: a
! THIS IS THE RIGHT WAY
! real, dimension(n) :: a
end subroutine inca
end interface
x = 0.
call inca(x,5)
print *, x
end program main
subroutine inca(a,n)
! this is a fortran77 style subroutine
dimension a(n)
do 10 j = 1, n
a(j) = a(j) + 1.
10 continue
return
end
$ gfortran y.f90
y.f90:6:10:
6 | subroutine inca(a,n)
| 1~~~~~~~~~~~~~~
Warning: Interface mismatch in global procedure 'inca' at (1): Shape mismatch in argument 'a'
--
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
--- Synchronet 3.21a-Linux NewsLink 1.2