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

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Thu Mar 7 13:22:03 UTC 2024


I am not the expert here, so hoping that others can chime in.  However, a quick seach has the following line in 18.3 Interoperability between Fortran and C entities:

If the type is character, the length type parameter is interoperable
if and only if its value is one.

Deferred length would seem to be at least potentially different than 1.

Cheers,


  *   Tom


From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Thursday, March 7, 2024 at 4:25 AM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Jean Perier <jperier at nvidia.com>
Subject: [EXTERNAL] [BULK] [J3] CFI descriptors for sequence associated BIND(C) assumed-length dummy arguments

CAUTION: This email originated from outside of NASA.  Please take care when clicking links or opening attachments.  Use the "Report Message" button to report suspicious messages to the NASA SOC.


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/0952fa37/attachment.htm>


More information about the J3 mailing list