Thanks, this is an easy hack which should do the trick.
It actually is in the original code.
I don’t use the value, but I need it to check if maybe is unallocated. See your comment here.
A more complete example what I’m trying to do would be this:
implicit none
character(:), allocatable :: not_used
call sub(not_used, "123")
call sub("1", "123")
contains
subroutine sub(useless_var, print_this)
class(*), intent(in) :: useless_var(..)
character(*), intent(in) :: print_this
print *, "should be 123: '", print_this, "'"
print *, "useless_var is unallocated", is_unallocated(useless_var)
end subroutine sub
logical function is_unallocated(var)
class(*), intent(in), optional :: var(..)
is_unallocated = .not. present(var)
end function is_unallocated
end
Followup question: Should I use type(*)
or class(*)
for the is_unallocated
function? What’t the difference beside bypassing a GFortran bug?