[J3] Matching only arguments that are C interoperable?

Jeff Hammond jehammond at nvidia.com
Tue Oct 25 08:07:59 UTC 2022

On 24Oct 2022, at 4:55 PM, Steve Lionel via J3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>> wrote:

External email: Use caution opening links or attachments

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.


Thanks, Steve.  That’s not the answer I was hoping for because I can do such things in C++ but I accept that this is the way things are and can design MPI interfaces around it and add the appropriate warnings to users about the consequences of bad behavior.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221025/3b8dd940/attachment-0001.htm>

More information about the J3 mailing list