Suppose an dummy argument is modified in a subroutine, and the subroutine doesn't care about its initial value. For a scalar of the standard numerical types (no components), intent(out)
would be correct, right?
Now, if the dummy argument is allocatable and the subroutine depends on its allocation status, or if it has components that are not modified by the subroutine but should maintain their initial values (i.e. not become undefined), or, similarly, if it's an array and not all elements are set in the subroutine... Then the proper intent would be intent(inout)
.
My question is what happens if the dummy argument is an assumed-size array (dimension(*)
)? Assuming that not all elements are modified in the subroutine and one wants the other elements to retain their initial values, would intent(out)
be appropriate? My reasoning is that the subroutine doesn't "know" the size of the array, so it cannot make the elements undefined as it can with a fixed-size array.
Does the standard say anything about this or are compilers free to "guess" for example that if I set A(23) = 42
, then all elements A(1:22)
can be made undefined (or NaN, or garbage...)?
Note: When I say "retain their initial values", I mean the values in the actual argument outside the subroutine. The subroutine itself doesn't care about the values of these elements, it never reads them or writes them.
intent(out)
even if a compiler won't actually "reset" those values. That's what Fortran specifies, not what you can "get away with". (More detail in the linked, but if that doesn't help you please edit the question and we can reevaluate duplicate.) – francescalusintent(out)
. My question is about what happens to the values of the actual argument outside the subroutine. I added a "note" to the question, hopefully that's enough? – Jellby