Passing in a longer array than a function expects

Thanks a lot @msz59 and @RonShepard for the examples.

Yes, legacy codes need to stay working, that’s given.

I was wondering for new codes in modern Fortran, when you would like to use this feature. It seems that the use cases are:

  • Want to pass in the whole array f(x) instead of an exact section f(x(1:5)).
  • I want to specify array slicing using sum(t1, 10), sum(t1(11), 10), sum(t2(1,3), 10*2), etc. instead of using sections sum(t1(1:10)), sum(t1(11:20)), sum(t2(1:10,3:4)).
  • Legacy codes that I do not want to modify

It seems that I would always prefer the sections, as to me at least it seems much more readable. I can definitely see how it was convenient in legacy codes however.

Note: changing of the rank (while keeping the total size the same) is a separate feature — that has several good use cases when you need to index an array in few different schemes, that otherwise one would have to emulate using associate and pointers, and I am not sure if there could be a performance penalty.

3 Likes