[J3] Matching only arguments that are C interoperable?
Jeff Hammond
jehammond at nvidia.com
Mon Oct 24 13:04:44 UTC 2022
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.
As best I can tell, I write specific interfaces with 16 dimensions (scalar+15D) times 15 (?) built-in types but that still leaves out C interoperable structs. It also fails miserably in contexts where there is more than one buffer argument, as noted in https://www.researchgate.net/profile/Jeffrey-Squyres/publication/221596873_A_Case_for_New_MPI_Fortran_Bindings/links/00b7d536bbaff31de5000000/A-Case-for-New-MPI-Fortran-Bindings.pdf.
Am I missing something or is there no way to resolve whether I have C interoperable arguments at compile-time?
Thanks,
Jeff
PS if it helps to think about this with code, the following compiles without error, which someone else thought was correct.
module m
type :: t
integer :: i
double precision :: d
integer :: j(10)
real :: r(100)
real, allocatable :: z(:)
end type t
interface
subroutine foo(t) bind(C)
implicit none
type(*), dimension(..) :: t
end subroutine foo
end interface
end module m
program main
use m
implicit none
type(t) :: x
call foo(x)
end program main
More information about the J3
mailing list