このコードがあれば
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
「foo2」の長さが20ではないため、コンパイルされず、コンパイラーは文句を言います
test.f90(17): error #7938: Character length argument mismatch. ['foo2']
call xx("foo2")
-----------^
サブルーチンのダミー len 仕様を変更せずに、どうすればこれを機能させることができますか? 中間変数を同じ長さで宣言し、呼び出し時にそれを渡すことは必須ですか?