(j3.2006) C-interoperable interface bodies
Van Snyder
van.snyder
Fri Feb 23 16:58:28 EST 2007
On Fri, 2007-02-23 at 15:27 -0600, Bill Long wrote:
> > I wrote:
> > I don't have a compiler that does BIND yet, but in the ones I have, when
> > I put an interface body in a module, they don't produce a symbol
> > definition:
> >
> > module A
> >
> > interface
> > subroutine P_A ( X )
> > real :: X
> > end subroutine P_A
> > end interface
> >
> > end module A
> >
> > #lf95 -c interfaceTest.f90
> > # nm interfaceTest.o
> > 00000000 T a_
>
> I get:
>
> % nm van.o
> 0000000000000000 t %%COMP_UNIT_BEGIN
> 0000000000000008 t %%FUNC_BEGIN_1
> 0000000000000080 t %%FUNC_END_1
> 0000000000000080 T __p_a_
> 0000000000000080 T a_
> %
Assuming the symbol __p_a arose from the interface body for P_A, I think
your compiler has a bug in it. There's no definition of P_A here, so I
don't think there ought to be a definition of __p_a in the .o file.
There is a declaration that an external subroutine known by the Fortran
name P_A might exist somewhere in the program -- but it's not even
required to exist so long as it isn't invoked or used as a target in a
pointer assignment statement.
If you embellish the example a little bit:
module A
interface
subroutine P_A ( X )
real :: X
end subroutine P_A
end interface
end module A
subroutine P_A ( X )
real :: X
end subroutine P_A
program Test_P_A
use A, only: P_A
real :: X
call P_A (x)
end program TEST_P_A
in separate files, do you get a duplicate-symbol-definition error from
your linker?
Here's what I get
from lf95: from NAG f95:
% nm *.o % nm *.o
interfaceTest.o: interfaceTest.o:
00000000 T a_
main.o: main.o:
00000000 R .jwe_ssn_MAIN__ U f90_finish
U jwe_xcop U f90_init
U jwe_xstp 00000000 T main
00000000 T MAIN__ U p_a_
U p_a_
p_a.o: p_a.o:
00000000 R .jwe_ssn_p_a_ 00000000 T p_a_
00000000 T p_a_
Notice that the symbol p_a is defined in the file p_a.o in both cases,
referenced in the main program in both cases and not even mentioned in
interfaceTest.o (where module A is defined) in both cases.
There are no complaints from the linker, in either case.
What do you get if you put "BIND(C,name="foobar")" after
"subroutine P_A (X)" both in the module and in the external subroutine
definition?
More information about the J3
mailing list