Re: generic INTERFACE and name clash
- From: Tobias Burnus <burnus@xxxxxxxx>
- Date: Mon, 24 Sep 2007 13:47:21 -0700
On 24 Sep., 21:08, "James Van Buskirk" <not_va...@xxxxxxxxxxx> wrote:
"Oskar Enoksson" <enok_tabort...@xxxxxxxxxxxxxx> wrote:I did as it was not yet reported and I feared that it might get
Someone else has reported it.
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
.
- Follow-Ups:
- Re: generic INTERFACE and name clash
- From: Oskar Enoksson
- Re: generic INTERFACE and name clash
- From: James Van Buskirk
- Re: generic INTERFACE and name clash
- References:
- generic INTERFACE and name clash
- From: Oskar Enoksson
- Re: generic INTERFACE and name clash
- From: James Van Buskirk
- Re: generic INTERFACE and name clash
- From: paul . richard . thomas
- Re: generic INTERFACE and name clash
- From: Oskar Enoksson
- Re: generic INTERFACE and name clash
- From: James Van Buskirk
- generic INTERFACE and name clash
- Prev by Date: Re: Passing complex
- Next by Date: Re: Passing complex
- Previous by thread: Re: generic INTERFACE and name clash
- Next by thread: Re: generic INTERFACE and name clash
- Index(es):
Relevant Pages
|