This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Module variable name
- From: Richard E Maine <Richard dot Maine at nasa dot gov>
- To: Salvatore Filippone <salvatore dot filippone at uniroma2 dot it>
- Cc: fortran at gcc dot gnu dot org
- Date: Thu, 13 Oct 2005 09:13:49 -0700
- Subject: Re: Module variable name
- References: <1129218267.3420.18.camel@localhost>
On Oct 13, 2005, at 8:44 AM, Salvatore Filippone wrote:
I had a Fortran module defining an explicit interface in which one of
the dummy arguments had the same name as the module itself
...
Question: is this specified by the standard?
Well, I'm a little unclear on exactly what you mean by "this". But
anyway...
Module names are specifically *NOT* in any special separate category in
the standard. A module name is just a global name and follows the same
rules as any other global name (external procedure names, etc). There
was once a proposal to make a separate class for module names, as they
are always syntactically distinct (a USE statement being the only place
they can appear other than the module/endmodule statements), but that
propossal did not pass. It is an oversimplification to say that you
can't have a module name be the same as the name of a dummy argument.
There is not a rule like that. But there are rules that do apply. I
would have to see the actual code - you haven't given enough
information for me to be sure. I think your code might be ok, based on
the description, but I'm not sure.
The short version is that you can't use the same name for 2 different
purposes in the same scoping unit. There are exceptions, but none
particularly relevant here. But your description doesn't make it clear
whether or not you actually are using both names in the same scoping
unit. I think maybe you aren't, but I can't tell for sure without
seeing code. A case like
module x
interface
subroutine sub(x)
end subroutine sub
end interface
end module x
is fine. That's because x is not used as a module name in the interface
body. The normal host association rules apply; thus within the
interface body, x is the dummy argument and cannot be used to refer to
the module x. But it is not used to refer to the module in the
interface body, so all is fine. (Perhaps confusing, but
standard-conforming).
But a case like
module whatever
interface
subroutine sub(x)
use x
end subroutine sub
end interface
end module whatever
is not standard-conforming because x is used for both purposes in the
same scoping unit.
--
Richard Maine | Good judgment comes from experience;
Richard.Maine@nasa.gov | experience comes from bad judgment.
| -- Mark Twain