Skip to content

Commit fcc0d33

Browse files
authored
Update gotchas.md (#454)
The "implied save" paragraph was not fully correct
1 parent e3d902c commit fcc0d33

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

source/learn/quickstart/gotchas.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,15 @@ c = 0
7878
```
7979
`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:
8080
```
81-
integer, save :: c=0
81+
integer, save :: c=0 ! "save" can be omitted, but it's clearer with it
8282
```
83-
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:
83+
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:
8484
```
8585
integer c
8686
data c /0/
87+
save c
8788
```
88-
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:
89-
```
90-
integer, save :: c=0 ! save could be omitted, but it's clearer with it
91-
```
89+
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.
9290

9391
*Note: an initialization expression of a derived type component is a fully different case:*
9492
```

0 commit comments

Comments
 (0)