From fcc0d335d831f2f6c4a71e2626dfffa4a22d93fe Mon Sep 17 00:00:00 2001 From: PierUgit Date: Sat, 24 Aug 2024 19:21:41 +0200 Subject: [PATCH] Update gotchas.md (#454) The "implied save" paragraph was not fully correct --- source/learn/quickstart/gotchas.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/learn/quickstart/gotchas.md b/source/learn/quickstart/gotchas.md index 0067a1fc00f..f3507438a3c 100644 --- a/source/learn/quickstart/gotchas.md +++ b/source/learn/quickstart/gotchas.md @@ -78,17 +78,15 @@ c = 0 ``` `integer :: c=0` is actually a one-shot **compile time initialization**, and it makes the variable persistent between calls to `foo()`. It is actually equivalent to: ``` -integer, save :: c=0 +integer, save :: c=0 ! "save" can be omitted, but it's clearer with it ``` -The `save` attribute is equivalent to the C `static` attribute to make a variable persistent, and it is *implied* in the case the variable is initialized. This is a modernized syntax (introduced in Fortran 90) compared to the legacy (and still valid) syntax: +The `save` attribute is equivalent to the C `static` attribute used inside a function to make a variable persistent, and it is *implied* in the case the variable is initialized. This is a modernized syntax (introduced in Fortran 90) compared to the legacy (and still valid) syntax: ``` integer c data c /0/ +save c ``` -Old fortraners just know that the modernized syntax is equivalent to the legacy one, even when `save` is not specified. But as a matter of fact the *implied save* can be misleading to newcomers who are used to the C logic. That's why it is generally recommended to **always** specify the `save` attribute: -``` -integer, save :: c=0 ! save could be omitted, but it's clearer with it -``` +Old fortraners just know that the modernized syntax is equivalent to the legacy one, even when `save` is not specified. But as a matter of fact the *implied save* can be misleading to newcomers who are used to the C logic. That's why it is generally recommended to **always** specify the `save` attribute. *Note: an initialization expression of a derived type component is a fully different case:* ```