(j3.2006) C-interoperable interface bodies

Bill Long longb
Fri Feb 23 16:27:37 EST 2007



Van Snyder wrote:

>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 think I said that if you wrote both subroutines in Fortran then you 
get duplicate linker symbols.  (p is defined twice.)


As another set of data, for the test below I get:

>
>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_
%

>
>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".
>  
>
For this case I get (with bind(c) and the reference in the contained 
subroutine S):

% nm van2.o
0000000000000000 t %%COMP_UNIT_BEGIN
0000000000000000 t %%COMP_UNIT_BEGIN
000000000000000c t %%FUNC_BEGIN_1
000000000000000c t %%FUNC_BEGIN_2
0000000000000120 t %%FUNC_END_1
0000000000000080 t %%FUNC_END_2
0000000000000080 T __p_a_
00000000000000c0 T __p_s at a_
0000000000000080 T a_
                                 U foobar
00000000000000c0 T s at a_
%

Cheers,
Bill



>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.
>
>  
>

-- 
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

            

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://j3.scs.gmu.edu/pipermail/j3/attachments/20070223/1330bbac/attachment.html 



More information about the J3 mailing list