# Repeat count for modern-style initializations

**URL:** <https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386>\
**Category:** Help\
**Created:** [July 25, 2024, 6:09pm UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386 "2024-07-25T18:09:14Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 27, 2024, 3:10pm UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386/21 "2024-07-27T15:10:23Z")

</div>

> [@FortranFan](#):
>
> > [@Machalot](#):
> >
> > with
> > 
> > ```auto
> > real :: var = 0.0
> > 
> > ```
> 
> That is unlikely a “common suggestions for modernization”.
> 
> What might be `FORTRAN` code as
> 
> ```auto
> REAL VAR
> DATA VAR /0.0/
> 
> ```
> 
> will require analysis to ascertain whether the **“implied SAVE”** is really necessary. The [**refactoring**](https://en.wikipedia.org/wiki/Code_refactoring) decision will depend on this analysis.
> 
> More often than not, the **modern Fortran** replacement will be
> 
> ```auto
> real, parameter :: VAR = 0.0
> 
> ```
> 
> In a few cases, it might call for an object definition in the executable section of the code separate from the variable declaration:
> 
> ```auto
> ..
> real :: var
> ..
> var = 0.0
> 
> ```
> 
> In a few unfortunate situations, the modern Fortran replacement may need to
> 
> ` real, save :: var = 0.0 !<-- inform the reader explicitly the object has`

Excellent, we ended up with the following warning in LFortran after a few iterations:

```console
warning: Assuming implicit save attribute for variable declaration
 --> a.f90:2:9
  |
2 | real :: var = 0.0
  | ^^^^^^^^^ help: add explicit save attribute or parameter attribute or initialize in a separate statement

```

Which enumerates the same three cases that you mentioned. So this is good.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [July 27, 2024, 6:35pm UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386/22 "2024-07-27T18:35:07Z")

</div>

> [@certik](#):
>
> `[...] or initialize in a separate statement`

Perhaps the term “initialize” is a little confusing here. In fortran, “initialize” usually means at compile/link time, not at run time. The third alternative in this situation is a run time assignment statement. That is “initialization” in a mathematical or algorithm context, but not in a fortran context.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 27, 2024, 9:27pm UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386/23 "2024-07-27T21:27:52Z")

</div>

@RonShepard thanks for feedback. How would you formulate it, let’s say: “help: add explicit save attribute or parameter attribute or use a separate runtime assignment statement”?

---

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [July 28, 2024, 2:57am UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386/24 "2024-07-28T02:57:10Z")

</div>

Last time I put `SAVE` among the specification statements of a subroutine to save everything savable that was declared there, lfortran gave me a lot of warnings I had hoped it wouldn’t, and I had to put things like `real,save::` in all the declarations of variables.

Is there a chance that one day we could use something like `NO_SAVE` where we can now use `SAVE` if we wanted that effect?

---

<div class="post-metadata">

**Author:** ![Machalot](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@Machalot](https://fortran-lang.discourse.group/u/Machalot)\
**Post date:** [July 28, 2024, 7:41am UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386/25 "2024-07-28T07:41:21Z")

</div>

> [@Harper](#):
>
> Is there a chance that one day we could use something like `NO_SAVE` where we can now use `SAVE` if we wanted that effect?

I’ve always wondered why there’s no `nosave` to disable implicit `save`.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 28, 2024, 8:21am UTC](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386/26 "2024-07-28T08:21:26Z")

</div>

> [@Harper](#):
>
> Last time I put `SAVE` among the specification statements of a subroutine to save everything savable that was declared there, lfortran gave me a lot of warnings I had hoped it wouldn’t, and I had to put things like `real,save::` in all the declarations of variables.

That’s a bug, I just reported it: [Implement standalone `save` declaration line · Issue #4544 · lfortran/lfortran · GitHub](https://github.com/lfortran/lfortran/issues/4544), it should behave the same no matter where you put the explicit `save`. Update (12h later): and the bug is fixed. @Harper if you discover any other issue related to this, let us know.

[Previous page](https://fortran-lang.discourse.group/t/repeat-count-for-modern-style-initializations/8386.md?page=1)
