[J3] Question involving explicit initialization

Steidel, Jon L jon.l.steidel at intel.com
Sat May 4 12:59:42 EDT 2019


Hi Vipul,

The key here is that the variable i in sub1, and the variable I in sub2 are different variables; one is declared and initialized in the scope of sub1, the other is explicitly declared and initialized in the scope of sub2.  They have separate storage.  The only thing they have in common is their name.  As Bill said, neither can be accessed outside the module procedure in which they are declared.

Or am I missing the point of your question?

-jon

-----Original Message-----
From: J3 [mailto:j3-bounces at mailman.j3-fortran.org] On Behalf Of Vipul Parekh via J3
Sent: Saturday, May 4, 2019 12:13 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Vipul Parekh <parekhvs at gmail.com>
Subject: Re: [J3] Question involving explicit initialization

On Sat, May 4, 2019 at 11:00 AM Bill Long via J3 <j3 at mailman.j3-fortran.org> wrote:
>
>
> > On May 4, 2019, at 9:46 AM, Vipul Parekh via J3 <j3 at mailman.j3-fortran.org> wrote:
> >
> > Does the following code conform to the Fortran standard?
>
> Yes.  I don’t see any cause for doubt.
>
> In each subroutine the variable i is local. Initialization causes it to have the SAVE attribute.  Since there is no method for the value of i to be exposed outside the subroutine, I don’t see any value to incrementing it. But there are lots of examples of pointless codes that are standard conforming.   If i did not have the SAVE attribute, almost certainly the compiler would not generate code for the increment or allocate storage for i.
> ..

Thanks, Bill.

And yes, my concern is with the standard-conforming aspect and not the pointless instructions.

Consider this from the standard (reformatting and emphasis is be me):

--- begin text ---
  8.4 Initialization

1 The appearance of initialization in an entity-decl for an entity without
  the PARAMETER attribute specifies that the entity is a variable with
  explicit initialization.  Explicit initialization alternatively may be
  specified in a DATA statement unless the variable is of a derived type
  for which default initialization is specified. If initialization is =
  constant-expr, the variable is initially defined with the value specified
  by the constant-expr; if necessary, the value is converted according to
  the rules of intrinsic assignment (10.2.1.3) to a value that agrees in
  type, type parameters, and shape with the variable. *A variable, or part
  of a variable, shall not be explicitly initialized more than once in a
  program.* ..
--- begin text ---

Does the statement, "A variable, or part of a variable, shall not be explicitly initialized more than once in a program" apply to the code I showed in the initial note?  If not, can readers here provide input on the what is meant by "A variable, or part of a variable" and "program" in this sentence in the standard?  At first glance, the sentence looks rather confusing.

Thanks,
Vipul


More information about the J3 mailing list