[J3] CFI_establish and elem_len for zero-length character strings and empty types/structs
Bader, Reinhold
Reinhold.Bader at lrz.de
Fri Jul 23 10:02:16 UTC 2021
Given that for the case of a Fortran string we're talking about a
CHARACTER(len=*)
declaration in the Fortran interface which is non-interoperable anyway, permitting all elem_len values that can arise in Fortran would follow the principle of least surprise.
For zero-size C structs I would consider this more borderline; at most one could make a case for this being processor-dependent.
Regards
Reinhold
________________________________________
Von: J3 <j3-bounces at mailman.j3-fortran.org> im Auftrag von Tobias Burnus via J3 <j3 at mailman.j3-fortran.org>
Gesendet: Freitag, 23. Juli 2021 09:37:52
An: General J3 interest list
Cc: Tobias Burnus
Betreff: Re: [J3] CFI_establish and elem_len for zero-length character strings and empty types/structs
I wrote in reply to Malcolm:
> You wrote that "Fortran character strings of length zero are not interoperable". Can you pinpoint this in the standard for arguments passed as CFI array descriptor? From F2018's 18.3.6 (5) bullets (2)+(3) and 18.3.6 (6) it sounds as if it should be valid. But I likely missed some fineprint elsewhere.
On 22.07.21 20:01, Robert Corbett via J3 wrote:
> Paragraph 1 of Subclause 18.3.1
> of 18-007r1 states
>
> If the type is character, the length
> type parameter is interoperable
> if and only if its value is one.
I do know about this – but my impression was/is that this generic
requirement is relaxed for some use cases. (All quotes form 18-007r1.)
For instance, in "18.3.4 Interoperability of scalar variables"
"A named scalar Fortran variable is interoperable ... if it is
of type character its length is not assumed or declared by
an expression that is not a constant expression."
If I understood _you_ correctly, a variable or dummy argument
might have a constant length (per 18.3.4/5 and C1554/18.3.6)
but _due to 18.3.1_ the constant must _always_ be one?
So far I was under the impression that also, e.g., len=5 is permitted
in this case (since Fortran 2008).
Likewise, I was under impression that len != 1 is permitted
for len=* and len=: (and as const expr via 18.3.4 (quoted above)) in:
"C1554 If proc-language-binding-spec is specified for a procedure,
each of its dummy arguments shall be an interoperable
procedure (18.3.6) or a variable that is interoperable
(18.3.4, 18.3.5), assumed-shape, assumed-rank, assumed-type,
of type CHARACTER with assumed length, or that has
the ALLOCATABLE or POINTER attribute."
where 18.3.6 adds some more restrictions, also depending whether
the VALUE attribute is present.
* * *
If indeed only len=1 is permitted, then it should be made more clear
in the standard. (NB: The constant length in 18.3.{4,5} appeared first in
Fortran 2008, in Fortran 2003 only the 18.3.1 wording appeared.)
In any case, I have read it such that Fortran 2003 only permitted len=1
while Fortran 2008 (and 2018) permit in _some_ cases other lengths.
* * *
Thus:
If only len=1 is permitted, then I find the 2008/2018 wording very confusing.
On the other hand, if len != 1 is sometimes permitted, then it is
still unclear to me what makes len=0 invalid for CFI_cdesc_t.
At least I do not see this requirement in 18.3.6 (5) + (6)
nor elsewhere in the spec.
Tobias
More information about the J3
mailing list