Unable to recognize intent(in) correctly

Peng Yu pengyu.ut@gmail.com
Sat Jun 20 23:10:00 GMT 2015


Hi, gfortran compiles the following program without any error/warning messages.

$ cat main.f90
program main
  integer :: a
  a = 1
  call bar(a)
  print *, a
end program

subroutine bar(a)
  interface
    subroutine foo(a)
      integer :: a
    end subroutine
  end interface

  integer, intent(in) :: a
  !integer :: a
  !a = 2
  call foo(a)
end subroutine

subroutine foo(a)
  integer :: a
  a = 2
end subroutine


But gfortran shows an error when compiling the following program.
Wouldn't it better that gfortran shows errors in both examples? Why it
doesn't show errors in the first example.

$ gfortran -Wconversion-extra -fcheck=all -Wall
-ffree-line-length-none -fimplicit-none -o ./main.exe main1.f90
main1.f90:10.2:

  a = 2
  1
Error: Dummy argument 'a' with INTENT(IN) in variable definition
context (assignment) at (1)
$ cat main1.f90
program main
  integer :: a
  a = 1
  call bar(a)
  print *, a
end program

subroutine bar(a)
  integer, intent(in) :: a
  a = 2
end subroutine


-- 
Regards,
Peng



More information about the Fortran mailing list