Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BIND(C) on module procedure

41 views
Skip to first unread message

pmk

unread,
Jun 13, 2022, 4:31:57 PM6/13/22
to
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?

pmk

unread,
Jun 13, 2022, 5:21:53 PM6/13/22
to
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?

Thomas Koenig

unread,
Jun 13, 2022, 6:05:09 PM6/13/22
to
pmk <pmkla...@gmail.com> schrieb:
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.

pmk

unread,
Jun 13, 2022, 6:45:07 PM6/13/22
to
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_'

pmk

unread,
Jun 13, 2022, 6:58:54 PM6/13/22
to
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!
0 new messages