Actually, C++ like const reference is very similar to intent(in)
, but more important is the distinction between assumed shape, assumed size, explicit size array dummy arguments.
For explicit size and assumed size arrays the Fortran rules have several requirements, that (in combination with the possibility of an implicit interface) make it necessary to use classical pass-by reference using a pointer to the first element.
However, the compiler does not have to pass the pointer to the original array, it can pass a pointer to a temporary copy.
For more complex passing mechanisms, which require explicit interface, a descriptor is passed (or a pointer to a descriptor). Again, the descriptor can in fact be of a temporary copy of the array. But these advanced passing mechanisms, as the assumed shape arrays, allocatable and pointer array arguments, make it less likely to need the temporary.
The temporary is always created when the value
attribute is used. A pointer (or descriptor) to the temporary is passed.
If you use any of the intents, it shouldn't change much where no temporary was necessary. It is just a promise and the passing mechanism doesn't change.
When the temporary was necessary, the compiler can avoid one of the copies to or from the temporary if you specified intent(in)
or intent(out)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…