(j3.2006) C-interoperable interface bodies

Bill Long longb
Fri Feb 23 17:32:39 EST 2007


For your embellished example:

% cat van3.f90
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
% ftn -c van3.f90
% nm van3.o
0000000000000000 t %%COMP_UNIT_BEGIN
0000000000000000 t %%COMP_UNIT_BEGIN
0000000000000000 t %%COMP_UNIT_BEGIN
000000000000000c t %%FUNC_BEGIN_1
000000000000000c t %%FUNC_BEGIN_2
000000000000000c t %%FUNC_BEGIN_3
0000000000000080 t %%FUNC_END_1
0000000000000088 t %%FUNC_END_2
0000000000000118 t %%FUNC_END_3
                 U _END
0000000000000080 T __p_a_
0000000000000080 T __p_p_a_
00000000000000c0 T __p_test_p_a_
0000000000000080 T a_
00000000000000c0 T main
0000000000000080 T p_a_
00000000000000c0 T test_p_a_
%


% cat van4.f90
module A

  interface
    subroutine P_A ( X ) bind(c,name="foobar")
      real :: X
    end subroutine P_A
  end interface

end module A

subroutine P_A ( X ) bind(c,name="foobar")
  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
% ftn -c van4.f90
% nm van4.o
0000000000000000 t %%COMP_UNIT_BEGIN
0000000000000000 t %%COMP_UNIT_BEGIN
0000000000000000 t %%COMP_UNIT_BEGIN
000000000000000c t %%FUNC_BEGIN_1
000000000000000c t %%FUNC_BEGIN_2
000000000000000c t %%FUNC_BEGIN_3
0000000000000080 t %%FUNC_END_1
0000000000000088 t %%FUNC_END_2
0000000000000178 t %%FUNC_END_3
                 U _END
0000000000000080 T __p_a_
0000000000000080 T __p_foobar
0000000000000080 T __p_p_a_
0000000000000100 T __p_test_p_a_
0000000000000080 T a_
0000000000000080 T foobar
                 U foobar
0000000000000100 T main
0000000000000080 T p_a_
0000000000000100 T test_p_a_
%

If you drop the -c from the compile, both versions like with no errors.

Cheers,
Bill




Van Snyder wrote:

>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?
>
>_______________________________________________
>J3 mailing list
>J3 at j3.scs.gmu.edu
>http://j3.scs.gmu.edu/mailman/listinfo/j3
>  
>

-- 
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/1bc56080/attachment.html 



More information about the J3 mailing list