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

Steidel, Jon L jon.l.steidel at intel.com
Tue Jan 8 11:31:50 EST 2019


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<mailto:cdchen at ca.ibm.com>
http://www.ibm.com/software/awdtools/fortran/xlfortran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20190108/f92a34eb/attachment.html>


More information about the J3 mailing list