[J3] Passing an element of an assumed shape array to an assumed size dummy array
Malcolm Cohen
malcolm at nag-j.co.jp
Mon May 12 11:10:04 UTC 2025
There are multiple ways to do this:
1. Pass the whole assumed-shape array (no copying) to the assumed-size array, with the element number you want to start at as a separate argument. You’re already passing leading-dimension etc info so IMO that’s not a big deal.
2. Use rank-remapping pointer assignment to construct the view you want, and pass that.
All these old uses of sequence association were (as admitted in that thread) hard to understand and thus maintain. I do not think that extending sequence association to additional cases is a productive direction. We want things to be more reliable, not just add more stuff that works like the old F66/77 stuff did, which was notorious for bugs in programs when passing arguments.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Pierre Hugonnet via J3
Sent: Monday, May 12, 2025 6:41 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Pierre Hugonnet <pieru at ugo235.fr>
Subject: Re: [J3] Passing an element of an assumed shape array to an assumed size dummy array
There are actually cases where passing an element and counting on sequence association is still useful, and where passing an array section instead would result in copy-in/copy-out, thus hurting the performances. I have given an example here:
https://fortran-lang.discourse.group/t/array-element-actual-argument-assumed-size-dummy/9649/3?u=pieru
Pierre
Le 11.05.2025 21:22, Van Snyder via J3 a écrit :
On Sat, 2025-05-10 at 21:07 -0700, Robert Corbett via J3 wrote:
There is no incompatibility with FORTRAN 66 or FORTRAN 77. The restriction on passing a scalar actual argument to an array dummy arguments applies only to assumed-shape, pointer, or polymorphic arrays (see the first dotted item in paragraph 14 of Subclause 15.5.2.5). Therefore, the only incompatibility with FORTRAN 66 or FORTRAN 77 codes is with FORTRAN 66 or FORTRAN 77 codes that include assumed-shape, pointer, or polymorphic arrays.
Would it be useful to carve out an exception to use an element of a contiguous assumed-shape array (or pointer) as the start of a sequence association?
Probably not, because the actual argument is necessarily in a scope using stuff from Fortran 90 onward so there's no excuse not to write x(10:).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250512/34a4c62b/attachment-0001.htm>
More information about the J3
mailing list