Showing results for 
Search instead for 
Did you mean: 
New Contributor I

error with INTENT

I am using Fortran Compiler .  The following program compiles and runs without any errors.  However, there is a bug because a variable declared as INTENT(in) is passed to a subroutine where it is INTENT(inout).  Can the latest version of the compiler catch this bug?


module mymod
   pure subroutine myplus( a, b, c )
   implicit none
   integer,intent(inout):: a   !!!
   integer,intent(in):: b
   integer,intent(out):: c
      a = a * 2
      c = a + b
   end subroutine myplus
   pure function myadd( a, b ) result(c)
   implicit none
   integer,intent(in):: a, b
   integer c
      call myplus( a, b, c )  ! ERROR: a is intent(in), goes to intent(inout)
   end function myadd

end module mymod
program test_intent
use mymod, only: myadd
implicit none
integer a, b
   a = 1
   b = 2
   write(*,*) myadd(a, b)
end program test_intent


0 Kudos