(j3.2006) C-interoperable interface bodies
Van Snyder
van.snyder
Fri Feb 23 15:07:14 EST 2007
Aleks wrote:
>module A
> interface
> subroutine p_A(f, a) bind(c, name='p')
> type(c_ptr) :: f
> integer, value :: a
> end subroutine p1
>end module
>
>module B
> interface
> subroutine p_B(f, a) bind(c, name='p')
> type(c_ptr) :: f
> integer, value :: a
> end subroutine p1
>end module
and Bill said this would cause duplicate linker symbol errors.
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_
If I add a call to P_A, I get a symbol reference, not a definition:
module A
interface
subroutine P_A ( X )
real :: X
end subroutine P_A
end interface
contains
subroutine S
real :: X
call P_A (x)
end subroutine
end module A
# nm interfaceTest.o
00000000 T a_
00000010 T a.s_
00000000 R .jwe_ssn_a.s_
U p_a_
NAG f95 produces no linker symbols in the first case, and produces only
the following in the second case:
# nm interfaceTest.o
00000000 T a_MP_s
U p_a_
What I hope would happen if a processor could do BIND(C,name="foobar")
is that the "U p_a_" would be replaced by "U foobar", not "T foobar".
As I remarked earlier, interface bodies are procedure DECLARATIONS, not
procedure DEFINITIONS, so they shouldn't produce linker symbol
definitions. In fact, they ought not to produce linker symbol
anythings; the processor should wait to see whether the procedures they
declare are referenced (by invocations or pointer assignments), and
produce linker symbol REFERENCES, not linker symbol DEFINITIONS at those
points. Independently of whether what Andy's colleague wants to do with
printf ought to work, Aleks's example ought to work. I think we got at
least this little bit wrong.
--
Van Snyder | What fraction of Americans believe
Van.Snyder at jpl.nasa.gov | Wrestling is real and NASA is fake?
Any alleged opinions are my own and have not been approved or
disapproved by JPL, CalTech, NASA, the President, or anybody else.
More information about the J3
mailing list