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" is not of length 20, and the compiler complains
test.f90(17): error #7938: Character length argument mismatch. ['foo2']
call xx("foo2")
-----------^
How can I make this thing work, without modifying the subroutine dummy len specification ? Is it mandatory to have an intermediate variable declared with the same length and pass that at call time ?