What is the explicit difference between the fortran intents (in,out,inout)?

前端 未结 3 1542
慢半拍i
慢半拍i 2020-12-01 12:57

After searching for a while in books, here on stackoverflow and on the general web, I have found that it is difficult to find a straightforward explanation to the real diffe

3条回答
  •  醉话见心
    2020-12-01 13:05

    • intent(in) - looks like pass by value (and changes of this are not reflected in outside code) but is in fact pass by reference and changing it is prohibited by the compiler. But it can be changed still.
    • intent(out) - pass somehow by reference, in fact a return argument
    • intent(inout) - pass by reference, normal in/out parameter.

    Use intent(out) if is is plain out, to document your design. Do not care for the very little performance gain if any. (The comments suggest there is none as intent(in) is technically also pass by reference.)

提交回复
热议问题