Closed milancurcic closed 4 years ago
I will need some help linking to the user survey that @sblionel mentioned (I participated in it, and I read the results back then, but now I can't find it anywhere).
I will also need help suggest a specific and formal addition/change to the standard.
@milancurcic thank you for the proposal. The first draft looks good to me.
I will also need help suggest a specific and formal addition/change to the standard.
I am not sure what you mean.
Should the following cases be discussed in the draft:
1) What is the behavior of present
?
subroutine foo(dummy)
integer, intent(in), optional :: dummy = 0
print*, present(dummy) ! = .true. if dummy provided, .false. otherwise
end subroutine
2) How does dummy
behave when it is optional
and allocatable
?
subroutine foo(dummy)
integer, allocatable, intent(in), optional :: dummy(:) = [ 0, 0]
if ( .not. present(dummy)) then
allocate(dummy(5)) !I intentionaly used a dim of 5, instead of 2
dummy = 1
end if
end subroutine
I think your proposal has no problem when intent(inout || out), optional
is used since the argument is not provided
@jvdp1 Anything and everything we can think of that seems relevant should be discussed - both of those questions are worthy of mention.
My opinions would be:
present()
would always return true for an argument with a default.My position is that a default value has exactly the same meaning as if the caller passed that value as the corresponding actual argument, with all the existing rules applied. Indeed, I would expect a compiler to implement it this way, doing the substitution at the call and not inside the procedure being called.
First draft of the proposal to set default value for optional arguments (#22).