if i have this code
module test
contains
subroutine xx(name)
character(len=20), intent(in), optional :: name
if (present(name)) then
print *, name
else
print *, "foo"
endif
end subroutine
end module
program x
use test
call xx()
call xx("foo2")
end program
It will not compile since "foo2" has no length 20, and the compiler complains
test.f90(17): error
call xx("foo2")
How can I make this work without changing the specification of the dummy len subroutine? Is it necessary to have an intermediate variable declared with the same length and pass it during the call?
source
share