(j3.2006) (SC22WG5.3708) Comment on N1761
Bill Long
longb at cray.com
Wed Dec 3 11:29:07 EST 2008
Reinhold Bader wrote:
>
> before taking this offline, I'd like to understand something about BIND(C)
> which other people might know ...
>
> Take the following example program:
>
> module mod_label_interf
> use, intrinsic :: iso_c_binding
> implicit none
> interface foo
> subroutine foo_1(x, n, i) bind(c, name='Foo')
> import :: c_float, c_int
> real(c_float) :: x
> integer(c_int), value :: n, i
> end subroutine
> subroutine foo_2(x, n, i) bind(c, name='Foo')
> import :: c_float, c_int
> real(c_float) :: x(*)
> integer(c_int), value :: n, i
> end subroutine
> end interface
> end module
> program label_interf
> use mod_label_interf
> implicit none
> integer(c_int) :: i
> real(c_float) :: xx, xxx(3)
> i = 2
> call foo(xx, 1, i)
> call foo(xxx, 3, i)
> write(*, *) xx
> write(*, *) xxx
> end program
>
> together with the C implementation
>
> #include <math.h>
>
> void Foo(float *x, int n, int i) {
> int j;
> for (j=0; j<n; j++) {
> *(x+j) = (float) (i + j) + 0.1;
> }
> }
>
> This code is accepted by various processors and executes in accordance with my
> personal expectations (for what that is worth :-)).
> It is not accepted by NAG's compiler, and also not by IBM xlf. NAG's error message is
>
> Error: label_interf.f90: Duplicate binding label 'Foo' for external procedure FOO_2 and external procedure FOO_1
>
This error message is consistent with the Fortran 2003 rules. An
(non-abstract) interface declares the procedure name to be external.
However, in the case of a separate binding label, that rule is being
changed in Fortran 2008 to be the way you want it. If there is a
separate binding label then the procedure's name becomes a local name,
not external.
Cheers,
Bill
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120
More information about the J3
mailing list