I have two subroutine. One calls the other and the both have the same optional parameter:
program main
call a()
call a(7)
contains
subroutine a(var)
implicit none
integer, intent(in), optional :: var
call b(var)
end subroutine
subroutine b(var)
implicit none
integer, intent(in), optional :: var
if(present(var)) then
write (*,*) "var = ", var
else
write (*,*) "not given"
endif
end subroutine
end program main
In the first call of a
gives var
to b
even though it is not given. I tried this in gfortran and ifort and it seems to work. I am wondering though:
Is this valid standard-fortran or am I just abusing some loophole here?