[J3] CFI descriptors for sequence associated BIND(C) assumed-length dummy arguments

Jean Perier jperier at nvidia.com
Thu Mar 7 09:25:06 UTC 2024


Hello,

I would like to confirm the intended behavior of the following program:

```
module m
  interface
    subroutine c_defined_procedure(x, n) bind(c)
      integer :: n
      character(*) :: x(n)
    end subroutine
  end interface
contains
  subroutine test(x)
    character(*) :: x(10, 20)
    call c_defined_procedure(x, 100)
    call c_defined_procedure(x(1,1), 100)
  end subroutine
end module
```

Should the cfi descriptors prepared when calling "c_defined_procedure" both be descriptors for an entity of rank and shape 100 (dummy argument shape), or should it be a descriptor for a rank-2 entity with shape (10, 20) in the first call, and a descriptor for a scalar in the second call (actual argument shape)?

There is no consensus: xlf does the former (uses dummy argument shape) while ifort does the latter (uses actual argument shape).

This program is legal since sequence association allows passing a character actual argument to a dummy character with a different shape and rank (F2023 section 15.5.2.12), and because assumed-length character can be passed in BIND(C) interface (section 18.3.7 explicitly mentions them and mandates they must be passed as CFI descriptor). Note that gfortran incorrectly refuses the second case of sequence association because of the rank mismatch, and NAG incorrectly reports assumed-length arguments as not allowed in BIND(C) interface.

I think the standard gives right to ifort (using actual argument shape) since 18.3.7 says: "In this C descriptor, the members other than attribute and type shall describe an object with the same characteristics as the intended effective argument.". But I am not completely clear with regards to the distinction between effective and actual arguments, and it could be a bit surprising to get a descriptor of any rank on the C side for some users.

What do you think the behavior should be?

Jean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240307/bd30bc68/attachment.htm>


More information about the J3 mailing list