@@ -106,9 +106,14 @@ compatibility.
106
106
107
107
4.1 present()
108
108
109
- When the optional dummy argument has an initializer, the function
110
- present() will return .true., even if the actual argument is not passed
111
- by the caller.
109
+ There are two possible behaviors of the function present() when an
110
+ initializer is provided.
111
+
112
+ The first behavior would be that the function present() always returns
113
+ .true. when the optional dummy argument has an initializer, and
114
+ independently of the fact that an actual argument is passed or not
115
+ by the caller. Therefore, with such a behavior, the function present()
116
+ becomes useless for optional arguments with a default value.
112
117
113
118
Example:
114
119
@@ -120,6 +125,22 @@ Example:
120
125
print*, present(b) !always .true. due to the initializer
121
126
end function foo
122
127
128
+ The second behavior would be that the function present() returns
129
+ .true. or .false. when an actual argument is passed or not by the
130
+ caller, and independently of the fact that the optional dummy
131
+ argument has, or hasn't an initializer.
132
+
133
+ A use case of this behavior of the function present() could be:
134
+
135
+ real function foo(a, b)
136
+ real, intent(in) :: a
137
+ real, intent(in), optional :: b = 1.234
138
+ if (present(b)) then
139
+ ... !expensive input validation here
140
+ end if
141
+ ...
142
+ end function foo
143
+
123
144
124
145
5. Further discussion
125
146
0 commit comments