[J3] CFI_establish and elem_len for zero-length character strings and empty types/structs
Malcolm Cohen
malcolm at nag-j.co.jp
Thu Jul 22 08:53:38 UTC 2021
Hi Tobias,
>Likewise,
>type, bind(C) :: t; end type
This is not valid Fortran.
>and
>struct t {};
And this is not valid C according to the syntax in 6.7.2.1 of C 2018.
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.
So it’s not immediately obvious that this is a defect that needs correction. Though admittedly zero-size arrays and empty structures are not uncommon extensions to C, so permitting elem_len to be zero might be a good idea on its own merits.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Tobias Burnus via J3
Sent: Thursday, July 22, 2021 4:41 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Tobias Burnus <burnus at net-b.de>
Subject: [J3] CFI_establish and elem_len for zero-length character strings and empty types/structs
Hi all,
"" or ["", ""] has len(...) == 0. For the C array descriptor,
that matches elem_len = 0.
Likewise,
type, bind(C) :: t; end type
and
struct t {};
have c_sizeof()/sizeof() == 0, which implies elem_len = 0.
However, CFI_establish requires:
"elem_len – If type is equal to CFI_type_struct, CFI_type_other, or a Fortran
character type code, elem_len shall be greater than zero and equal to the
storage size in bytes of an element of the object."
The other CFI_... functions do not have the > 0 requirement (or != 0, as
size_t is unsigned and, hence, implies >= 0).
Tobias
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: 30 St. Giles, Oxford, OX1 3LE, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice> for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210722/5af09cb5/attachment.htm>
More information about the J3
mailing list