Direct indexing of function return value in Fortran

前端 未结 3 783
南旧
南旧 2020-12-02 00:30

Is there possibility to use indexing directly on a function\'s return value? Something like this:

readStr()(2:5)

where readStr()

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 01:22

    You can avoid declaring another variable if you use associate. Whether it is any better or clearer than a temporary variable must be decided by the user. The result has to be stored somewhere anyway.

     associate(str=>readStr())
       print *, str(2:5)
     end associate
    

    It will not be very useful for this specific case with a potentially long string but might be more useful for other similar cases that get linked here as duplicates.

提交回复
热议问题