From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D3E5838515F4; Mon, 5 Apr 2021 23:18:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3E5838515F4 From: "everythingfunctional at protonmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/99922] New: Bind(C) with assumed length character should work Date: Mon, 05 Apr 2021 23:18:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: everythingfunctional at protonmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Apr 2021 23:18:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99922 Bug ID: 99922 Summary: Bind(C) with assumed length character should work Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: everythingfunctional at protonmail dot com Target Milestone: --- As of (at least) Fortran 2018, bind(C) should be allowed for procedures with assumed length character variables, as one can pass CFI_cdesc_t* from the C side and it's supposed to work. MWE below ! main.f90 program main implicit none interface subroutine say_hello_c() bind(C) end subroutine end interface call say_hello_c() end program ! say_hello_fortran.f90 subroutine say_hello_fortran(name) bind(C) use iso_c_binding, only: c_char implicit none character(len=3D*, kind=3Dc_char), intent(in) :: name print *, "Hello from Fortran, " // name // "!" end subroutine ! say_hello_c.c #include #include extern void say_hello_fortran(CFI_cdesc_t * name_descriptor); void say_hello_c() { char * name =3D "World"; CFI_cdesc_t name_descriptor; int error_code =3D CFI_establish( &name_descriptor, name, CFI_attribute_other, CFI_type_char, strlen(name), 0, NULL); say_hello_fortran(&name_descriptor); } Compiling say_hello_fortran.f90 gives the error say_hello_fortran.f90:1:33: 1 | subroutine say_hello_fortran(name) bind(C) | 1 Error: Character argument =E2=80=98name=E2=80=99 at (1) must be length 1 be= cause procedure =E2=80=98say_hello_fortran=E2=80=99 is BIND(C) But the relevant text from the standard says (from section 18.3.6): any dummy argument without the VALUE attribute corresponds to a formal parameter of the prototype that is of a pointer type, and either the dummy argument is a nonallocatable nonpointer variable of type CHARACTER with assumed character length and the formal parameter is a pointer to CFI_cdesc_t, So this is supposed to be allowed, and I can confirm that I can compile and execute the above example and obtain the expected result with Intel (ifort = and icc). output of gfortran --version: GNU Fortran (Ubuntu 10.2.0-13ubuntu1) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=