[J3] Question involving explicit initialization
Vipul Parekh
parekhvs at gmail.com
Sat May 4 12:13:22 EDT 2019
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