[J3] please try running this program

Steidel, Jon L jon.l.steidel at intel.com
Tue Oct 25 14:33:27 UTC 2022


I believe the components within a derived type are in a unique scope, but other variables used within the derived type definition are in the host scope.  The components are declared in the scope of the derived type.  The variables used in the declarations of the components are not.

-jon

From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Steve Lionel via J3
Sent: Monday, October 24, 2022 8:01 PM
To: j3 at mailman.j3-fortran.org
Cc: Steve Lionel <steve at stevelionel.com>
Subject: Re: [J3] please try running this program


On 10/24/2022 8:45 PM, Malcolm Cohen via J3 wrote:
We did not change the scoping rules for this in Fortran 2018. And we know this because we did not list such a change in the compatibility clauses.

I believe this, but I think I understand why Bob thought otherwise. I'll admit that sometimes the fine points elude me, but...

A derived type definition is a scoping unit (3.123). The scope of a local variable is an inclusive scope (19.4).  Inclusive scope is "nonblock scoping unit plus every block scoping unit whose host is that scoping unit or that is nested within such a block scoping unit" (3.87). References to N2209.

I read this as saying that the scope of a variable whose implicit declaration is inside a derived type definition is that type definition. If there are words that say otherwise, I haven't found them yet.

Why is a derived type definition a scoping unit? Is it to restrict the scope of its named components? If so, it seems to me that has some unwanted side-effects.

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221025/5b6ae076/attachment.htm>


More information about the J3 mailing list