[J3] Matching only arguments that are C interoperable?

Steve Lionel steve at stevelionel.com
Mon Oct 24 13:55:38 UTC 2022


On 10/24/2022 9:04 AM, Jeff Hammond via J3 wrote:

> type(*), dimension(..) matches everything, which means that the C code on the receiving end of this will get things that it cannot process.  This forces libraries like MPI to error at runtime, which is not ideal.
>
> Is there a way to filter out non-C-interoperable types?  For example, if I had a way to write an interface that matches only scalars and arrays of built-in types, and an interface that matches only C interoperable structs, then the other cases will fail to compile or link.

The C descriptor, which is used for dimension(..), separates out 
interoperable and non-interoperable types in the type member. There are 
distinct type values for an interoperable struct (CFI_type_t) and "none 
of the above" (CFI_type_other). When type(*) is used, it's the 
responsibility of the caller to make sure the called procedure 
understands any possible type. I might imagine that a Fortran compiler 
could check (maybe needs to do this at runtime?) if a non-interoperable 
argument is passed by C descriptor, but as it stands the onus for this 
is on the user.

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221024/4a84b949/attachment.htm>


More information about the J3 mailing list