[J3] Is BIND (C [ , NAME = scalar-default-char-constant-expr ]) where scalar-default-char-constant-expr has zero length legal?

Bill Long longb at cray.com
Tue Jan 8 12:16:09 EST 2019


The standard has a three-way decision scheme for NAME=.

1) NAME= is specified and the character expr  has nonzero length after removing leading and trailing blanks.  => The binding label for the routine is the trimmed name specified by the character expr (which is required to be acceptable to the companion processor). 

2) NAME= is NOT specified in the BIND attribute. => The binding name is the Fortran name in lower case. 

3) Otherwise (i.e. not 1 or 2), there is no binding label.  The external name should be the same as would have been the case if there were no BIND attribute. 

name=“” comes under option 3. However the processor expresses the external name for non-BIND procedures is used in that case.   BIND can have other effects (limitations on arguments, etc) so it is not as if there were no BIND.  Only that the external symbol table entry for the name of the routine is as if there were no BIND. 

Cheers,
Bill


> On Jan 8, 2019, at 10:31 AM, Steidel, Jon L via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
> Hi Daniel,
>  
> Ifort (and NAG 6.1) appear to treat this as if NAME= was not specified.  When I simplified the test case to
>  
> program main
> use iso_c_binding
> interface
>   subroutine foo (a) bind(c,name = "")
>     real a
>   end
> end interface
>  
> call foo (1.0)
> end
>  
> Both compilers compile without error or warning, and fail in the link/load step with an undefined reference to “foo” or “foo_”.  So it looks like the Fortran name is used when NAME= is a zero length string.
>  
> -jon
> From: J3 [mailto:j3-bounces at mailman.j3-fortran.org] On Behalf Of Daniel C Chen via J3
> Sent: Tuesday, January 8, 2019 11:06 AM
> To: General J3 interest list <j3 at mailman.j3-fortran.org>
> Cc: Daniel C Chen <cdchen at ca.ibm.com>
> Subject: [J3] Is BIND (C [ , NAME = scalar-default-char-constant-expr ]) where scalar-default-char-constant-expr has zero length legal?
>  
> Consider the following code example:
> 
> module example
> 
> abstract interface
> subroutine sighandler_t(signum) bind(c)
> integer, value :: signum
> end subroutine
> end interface
> 
> contains
> 
> subroutine foo
> call bar(sighandler) 
> end subroutine
> 
> subroutine bar(proc)
> procedure(sighandler_t) :: proc
> end subroutine
> 
> subroutine sighandler(signum) bind(c,name='') ! NAME has zero length
> integer, value :: signum
> print *, signum
> end subroutine sighandler
> 
> end module
> 
> At 8.5.5, the standard says 
> 
> R808 language-binding-spec is BIND (C [ , NAME = scalar-default-char-constant-expr ])
> ...
> "If the value of the scalar-default-char-constant-expr after discarding leading and trailing blanks has nonzero
> length, it shall be valid as an identifier on the companion processor."
> 
> But the standard doesn't specify what if the scalar-default-char-constant-exprhas zero length.
> 
> Question: Should it be treated 
> 1. as if the NAME specified is not specified or 
> 2. the compiler should ignore the BIND attribute all together?
> 
> Thanks,
> 
> Daniel
> 
> XL Fortran Development, Fortran Standard Representative
> IBM Toronto Software Lab
> Phone: 905-413-3056 
> Tie: 969-3056 
> Email: cdchen at ca.ibm.com
> http://www.ibm.com/software/awdtools/fortran/xlfortran
> 

Bill Long                                                                       longb at cray.com
Principal Engineer, Fortran Technical Support &   voice:  651-605-9024
Bioinformatics Software Development                      fax:  651-605-9143
Cray Inc./ 2131 Lindau Lane/  Suite 1000/  Bloomington, MN  55425




More information about the J3 mailing list