You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/learn/quickstart/gotchas.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,17 +78,15 @@ c = 0
78
78
```
79
79
`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:
80
80
```
81
-
integer, save :: c=0
81
+
integer, save :: c=0 ! "save" can be omitted, but it's clearer with it
82
82
```
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:
84
84
```
85
85
integer c
86
86
data c /0/
87
+
save c
87
88
```
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.
92
90
93
91
*Note: an initialization expression of a derived type component is a fully different case:*
0 commit comments