(j3.2006) (SC22WG5.5615) RE: F08/0139??
Bill Long
longb
Mon Dec 21 15:59:15 EST 2015
On Dec 20, 2015, at 7:24 PM, Malcolm Cohen <malcolm at nag-j.co.jp> wrote:
> Interp says
>
>> Consider the program fragment:
>>
>> Subroutine s() Bind(C,Name='Hello')
>> Print *,'Hello'
>> End Subroutine
>> Subroutine s() Bind(C,Name='World')
>> Print *,'World'
>> End Subroutine
>>
>> This does not conform to Fortran 2003, and is not listed as an
>> extension in the Introduction to Fortran 2008, but the rules for
>> global names seem to indicate that this is now conforming.
>
>
> Bill Says:
>> You could alternatively make a module containing the text from the example,
>> and have the main program use the module and call s().
>
> Actually no. The "rules for global names" in the question means that these
> must be external subprograms, otherwise their names are Not global names.
> I'll accept that this is not completely obvious if you stop reading at the
> end of the program fragment! (Though I cannot recall us *ever* giving an
> example with internal or module procedures that did not either state that
> they were such, or with enough boilerplate around them to make them such, so
> I do think this reading is a trifle strained.)
Well, the ?strain? was because these might be actually called, and calling a subroutine like this requires an explicit interface. Normally people to not write INTERFACE blocks, but rather put such routines in a module. This avoids mistakes from having the interface interface information in multiple places. In this case, it appears there is no way to avoid writing an explicit interface block if you want to call either routine, and you cannot have both interfaces visible in any scope where S is called.
So, something like this example;
> cat test1.f90
Subroutine s() Bind(C,Name='Hello')
Print *,'Hello'
End Subroutine
Subroutine s() Bind(C,Name='World')
Print *,'World'
End Subroutine
subroutine sub_hello ()
interface
Subroutine s() Bind(C,Name='Hello')
End Subroutine
end interface
call s() ! Causes Hello to be printed
end subroutine sub_hello
subroutine sub_world ()
interface
Subroutine s() Bind(C,Name='World')
End Subroutine
end interface
call s() ! Causes World to be printed
end subroutine sub_world
program test
call sub_hello()
call sub_world()
end program test
> ftn test1.f90
> ./a.out
Hello
World
>
>
>> A whole, compilable and executable example would much better.
>
> Just inserting "containing the external subprograms" after "fragment" in the
> first quoted line above would IMO be more than sufficient.
That seems sufficient to rule out the invalid programs of which such fragment might have been a part.
Cheers,
Bill
>
> Cheers,
> --
> ..........................Malcolm.
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/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./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
More information about the J3
mailing list