Re: generic INTERFACE and name clash



On 24 Sep., 21:08, "James Van Buskirk" <not_va...@xxxxxxxxxxx> wrote:
"Oskar Enoksson" <enok_tabort...@xxxxxxxxxxxxxx> wrote:
Someone else has reported it.
I did as it was not yet reported and I feared that it might get
forgotten.

But is the concensus that my program should
be rejected or not? The bugreporter "burnus" seems to think it is legal
unless FOO is itself used as an actual argument.

No, I thought that it was probably invalid, however, I was not
completely sure and wanted to recheck the Fortran standard* -
especially after even NAG f95 and Lahey accepted it without any error.
The point I made was only: As actual argument it is ambiguous (unless
there is an explicit interface), otherwise it is not ambiguous. The
ambiguity has nothing to do with whether it is valid according to the
Fortran standard (except that a good standard should try hard to
disallow things which are ambiguous). And after re-reading parts of
the standard, I am convinced that it is invalid, unless someone points
out something in the standard which I overlooked or misinterpreted.

(* I have serious trouble to find the right spot in the standard and
to read it as written and not as it can be interpreted thinking
laterally.)


In the following example, there is no problem
about module procedures 'joe' having the same generic identifier
somehow, yet gfortran doesn't seem to mind it:

I don't see the contradiction (which the "yet" implies) between "there
is no problem" and "gfortran does not seem to mind it". The following
program is valid as JOE is never referred and thus this restriction
does not apply:

"Two or more accessible entities, other than generic interfaces or
defined operators, may have the same identifier only if the identifier
is not used to refer to an entity in the scoping unit." (Fortran 2003,
"11.2.1 The USE statement and use association")

And as the use-associated "JOE" is not used in the main program, there
is no problem.

MODULE M1
INTERFACE FOO
MODULE PROCEDURE joe
END INTERFACE
CONTAINS
SUBROUTINE joe(I)
INTEGER, INTENT(IN) :: I
WRITE(*,*) 'INTEGER'
END SUBROUTINE joe
END MODULE M1

MODULE M2
INTERFACE FOO
MODULE PROCEDURE joe
END INTERFACE
CONTAINS
SUBROUTINE joe(R)
REAL, INTENT(IN) :: R
WRITE(*,*) 'REAL'
END SUBROUTINE joe
END MODULE M2

PROGRAM P
USE M1
USE M2
CALL FOO(10)
CALL FOO(10.)
END PROGRAM P

(By the way, using "external bar; call bar(foo)" fails here as there
is no specific function FOO and a generic function cannot be used as
actual argument.)


Coming back to the initial program, which is the same as above except
with the word "JOE" replaced by "FOO".

USE makes both the specific FOO and the generic FOO identifier
accessible and the following applies:

"Two or more accessible entities, other than generic interfaces or
defined operators, may have the same identifier only if the identifier
is not used to refer to an entity in the scoping unit." (Fortran 2003,
"11.2.1 The USE statement and use association")

If one now uses the specific procedure FOO then the program is
invalid. Using the generic interface FOO is in principle ok, except
that both the specific and the generic subroutines have the same name.

One could now argue that in "CALL FOO(10)" only the generic interface
and not the specific procedure FOO is referred and that thus the
program is valid. However, one can also say FOO and FOO are the same
identifier and thus "CALL FOO(10)" is invalid. I am in favour of the
latter, which is also in line with the error given by Pathscale and
g95, and which implies that the original program is invalid (as
already written by James Van Buskirk and acknowledged by Paul Thomas).

Tobias

.



Relevant Pages

  • Re: generic INTERFACE and name clash
    ... Looks like the standard could need some clarification on this point. ... other than generic interfaces or ... may have the same identifier only if the identifier ... INTERFACE FOO ...
    (comp.lang.fortran)
  • Re: Identifying language concepts from sample code
    ... var foo = { ... 'Variable declaration', 'assignment', and 'object literal/initialiser' ... above assigns a reference to that one object to the Identifier - foo -. ... property being created on the execution context's Variable/Activation ...
    (comp.lang.javascript)
  • Re: Terms for method types?
    ... schema currently used in Javascript programming. ... through the identifier of the class from outside the class (when both should ... MyObject" (or, more precisely, "... ... function Foo() ...
    (comp.lang.javascript)
  • Re: variable, identifier, symbol?
    ... > then foo is a variable and an identifier and 'foo is a symbol whose ... > value is the value of the variable identified by the identifier foo. ... that the symbol 'define represents a special form. ...
    (comp.lang.scheme)
  • Re: NFS Security Question
    ... Subject: NFS Security Question ... >netgroup (which contains hosts for which the root password is only ... joe can get euid=0 via su since he doesn't know the password. ... >system-wide default login enviroment and a CWD of '/' on 'foo'. ...
    (Focus-SUN)