(j3.2006) Generic interface question
Van Snyder
Van.Snyder
Tue Mar 8 18:28:39 EST 2011
On Sat, 2011-03-05 at 01:27 -0800, malcolm at nag-j.co.jp wrote:
> The hairsplitting that we did here is fine. It doesn't add extra
> functionality as such though - it just means that the Fortran name is
> not an extra global identifier and so doesn't clash with other global
> identifiers.
>
> Which means that
>
> INTERFACE
> SUBROUTINE c_cos(x) BIND(C,NAME='cos'); END SUBROUTINE
> END INTERFACE
> and
> COMPLEX FUNCTION c_cos(x); COMPLEX x; c_cos=cos(x); END FUNCTION
>
> don't clash.
That example doesn't address the point I'm trying to resolve. It seems
that
program P
use A
use B
end program P
module A
interface
subroutine SA ( X ) bind (C, name = 'cf' )
real X
end subroutine SA
end interface
end module A
module B
interface
subroutine SB ( X ) bind (C, name = 'cf' )
real X
end subroutine SB
end interface
end module B
is not a valid program. The interface bodies for SA and SB are global
entities (according to 16.2p1). They have the same binding label (a
global identifier according to 16.2p1). According to 16.2p2, two
entities are prohibited from having the same binding label.
This is what we tried to allow by saying that the name of an external
procedure that has a binding label is a local name. It appears that we
did not succeed.
If we want this to work, and if it doesn't work now, one solution is to
say in 16.2p1 that procedures and common blocks with binding labels are
global entities. This excludes interface bodies. Does a procedure
pointer have a binding label if its interface is defined by an interface
body with a binding label? If so, even more work is needed. Maybe
"common blocks and nonpointer procedures with binding labels...."
Then, if we want to prohibit
interface G
subroutine G1 ( X ) bind(C, name = 'g' )
real X
end subroutine G1
subroutine G2 ( Y, Z ) bind(C, name = 'g' )
integer Y
complex Z
end subroutine G2
end interface G
we would need to add a constraint to 12.4.3.4.5 to prohibit procedures
that are accessible in the same scoping unit and have the same generic
identifier from having the same binding label.
If we want to allow SA and SB to have the same generic identifier the
condition would be that the characteristics of two procedures with the
same binding label and the same generic identifier have to be identical.
This would violate the requirement in 12.4.2.3p7 that a procedure shall
not have more than one explicit specific interface in a given scoping
unit. Taking out the part "if the interface is accessed by use
association" leaving "except that there may be more than one local name
for the procedure" would repair this.
More information about the J3
mailing list