Intel Fortran, gfortran, and g95 all compile and run the following program, which changes an intent(in) argument, giving output 4.
module m implicit none contains subroutine foo(i) integer, intent(in) :: i call increment(i) end subroutine foo subroutine increment(i) integer :: i ! integer, intent(in out) :: i ! will not compile if this line uncommented i = i+1 end subroutine increment end module m program main use m, only: foo implicit none integer :: i i = 3 call foo(i) print*,i end program main
When argument intents were introduced in Fortran 90, should there have been a restriction that an intent(in) argument can only be passed to other procedures as an intent(in) argument? Maybe this was not done because it would have prevented code using intent(in) from calling Fortran 77 code in many cases. Can this now be fixed by saying that passing an intent(in) variable to a procedure as an argument that is not intent(in) is obsolescent? Compilers would be required to warn about this, and users could turn such warnings into errors.