[J3] CFI_establish and elem_len for zero-length character strings and empty types/structs

Tobias Burnus burnus at net-b.de
Thu Jul 22 10:10:39 UTC 2021


Hi Malcom,

[zero-size/empty struct/type]
I concur that it is invalid – but admittedly missed when quickly trying 
it in C as the compiler accepted it by default without a warning as 
common extension. (In Fortran, the >= 1 component constraint you 
mentioned is in F2018's C1805 (R726).)

[Character strings]
On 22.07.21 10:53, Malcolm Cohen via J3 wrote:
> Similarly, C forbids arrays of size zero (“If the expression is a 
> constant expression, it shall have a value greater than zero.”), and 
> Fortran character strings of length zero are not interoperable.

I do see several restriction in both standards related to this and 
especially to zero-length strings, mostly involving either the address 
(as with C_LOC) or the passing the address to actual data directly as 
pointer to a contiguous byte stream (e.g. scalar, 
explicit-size/assumed-size array). But I see less restrictions regarding 
the CFI array descriptor.

I also note that in the CFI array descriptor description, the base_addr 
is not described in terms of an array but as pointer – in particular: 
"if the object has zero size, the value is not a null pointer but is 
otherwise processor-dependent." The latter implies that elem_len may be 
0 – which can only be the case for other, struct, or/and character.

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.

Tobias



More information about the J3 mailing list