(j3.2006) Multiple interfaces for same procedure

Malcolm Cohen malcolm
Tue Mar 8 20:05:16 EST 2011


Bill Long wrote:
>Is it allowed to have two interfaces for the same procedure accessible
>(excluding the submodule case)? For example:
>
>module modu
>    interface
>       subroutine sub(x)
>         real x
>       end subroutine sub
>    end interface
>end module modu
>
>subroutine sub(x)
>    use modu
>    real x
>    x = 2.3
>end subroutine sub

That is not two interfaces, it is one interface and one definition.

We have never allowed the definition of a procedure to access an interface for 
itself.  The subprogram SUB is defining a procedure SUB, which is already 
accessible via use association.

Here we are, 11.2.2p9
  "The local identifier of an entity made accessible by a USE statement shall 
not appear in any other nonexecutable statement that would cause any attribute 
(5.3) of the entity to be specified in the scoping unit that contains the USE 
statement, except [for some exclusions that don't apply to this example]."

If you have two interfaces for the same procedure, one in module A and one in 
module B, and a scoping unit uses both modules, that is valid "only if the 
identifier is not used" (11.2.2p8).  So except in the vacuous case, that is not 
allowed either.

>This gives no error with 3 compilers, but one compiler complains about
>the multiple definition of "sub".

The quoted text is not a constraint, so the compilers are off the hook.

>Somewhat more concerning is this example:
...
>In this case, the two accessible interfaces for SUB are actually
>*different*.  Even so, the same 3 compilers gave no error,

Unsurprisingly - if they don't even detect that you are declaring something 
accessed via use association, why would they go to the trouble of checking 
consistency.

> and the
>fourth one issued the same error as for the first example.

Right - that is the only error.  There is no requirement that if you access an 
interface for yourself via use association that the interface is consistent - 
the requirement is that you DON'T access an interface for yourself!

Cheers,
-- 
................................Malcolm Cohen, Nihon NAG, Tokyo. 




More information about the J3 mailing list