• BIND(C) on module procedure

    From pmk@21:1/5 to All on Mon Jun 13 13:31:55 2022
    What is the binding name of a module procedure supposed to be when no NAME= appears? Every compiler that I try applies some kind of name mangling that combines the module name with the procedure name in a distinct fashion for each compiler. And yet the
    standard seems to be pretty clear that the default binding name is just the procedure name in lower case. Are all the compilers non-conforming, or have I missed something in the standards?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From pmk@21:1/5 to pmk on Mon Jun 13 14:21:51 2022
    On Monday, June 13, 2022 at 1:31:57 PM UTC-7, pmk wrote:
    What is the binding name of a module procedure supposed to be when no NAME= appears? Every compiler that I try applies some kind of name mangling that combines the module name with the procedure name in a distinct fashion for each compiler. And yet the
    standard seems to be pretty clear that the default binding name is just the procedure name in lower case. Are all the compilers non-conforming, or have I missed something in the standards?

    More information: this all seems to work as expected with "BIND(C)", but not with "BIND(C,NAME='')" -- i.e., with an empty or blank name. But that case should be the same as "BIND(C)", yes?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to pmk on Mon Jun 13 22:05:05 2022
    pmk <pmklausler@gmail.com> schrieb:
    What is the binding name of a module procedure supposed to be
    when no NAME= appears? Every compiler that I try applies some kind
    of name mangling that combines the module name with the procedure
    name in a distinct fashion for each compiler. And yet the standard
    seems to be pretty clear that the default binding name is just the
    procedure name in lower case. Are all the compilers non-conforming,
    or have I missed something in the standards?

    If you use BIND(C) in lowercase, then the name of the procedure
    is the one you specified, in lowercase.

    Example:

    $ cat bind.f90
    module x
    contains
    subroutine foo() bind(c)
    end subroutine foo
    end module x
    $ gfortran -c bind.f90
    $ nm bind.o
    0000000000000000 T foo
    $ nagfor -c bind.f90
    NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101
    [NAG Fortran Compiler normal termination]
    $ nm bind.o
    0000000000000000 T foo
    U _GLOBAL_OFFSET_TABLE_
    0000000000000000 b __NAGf90_DefIO_3_Read
    0000000000000020 b __NAGf90_DefIO_3_Write
    0000000000000020 C x_

    Both compilers correctly use "foo" as the binding name.

    What you observed probably was the "normal" name mangling, without
    bind(c). That is indeed compiler dependent.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From pmk@21:1/5 to pmk on Mon Jun 13 15:58:52 2022
    On Monday, June 13, 2022 at 3:45:07 PM UTC-7, pmk wrote:
    What has me concerned is that the behavior of BIND(C,NAME='') is not the same as BIND(C) with no NAME= at all.

    Oh, ok, I understand that text in 18.0.2 now. In the case of BIND(C,NAME=''), *there is no binding label*. Never mind!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From pmk@21:1/5 to All on Mon Jun 13 15:45:05 2022
    What has me concerned is that the behavior of BIND(C,NAME='') is not the same as BIND(C) with no NAME= at all.

    $ cat module-binding-1.f90
    module m
    contains
    subroutine foo() bind(c,name='')
    print *, 'works'
    end subroutine
    end module
    $ cat module-binding-2.f90
    program test
    interface
    subroutine foo() bind(c,name='')
    end subroutine
    end interface
    call foo
    end program
    $ gfortran -c module-binding-[12].f90
    $ nm module-binding-[12].o

    module-binding-1.o:
    U _GLOBAL_OFFSET_TABLE_
    0000000000000000 T __m_MOD_foo
    U _gfortran_st_write
    U _gfortran_st_write_done
    U _gfortran_transfer_character_write

    module-binding-2.o:
    0000000000000000 t MAIN__
    U _GLOBAL_OFFSET_TABLE_
    U _gfortran_set_args
    U _gfortran_set_options
    U foo_
    000000000000000c T main
    0000000000000000 r options.0.3877
    $ gfortran module-binding-[12].o
    /usr/bin/ld: module-binding-2.o: in function `MAIN__': module-binding-2.f90:(.text+0x5): undefined reference to `foo_'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)