Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit save and floating point literal gotchas #731

Merged
merged 5 commits into from
Sep 6, 2024
Merged

Conversation

pmocz
Copy link
Member

@pmocz pmocz commented Sep 6, 2024

Implicit saves (https://fortran-lang.org/learn/quickstart/gotchas/#implied-save) is a gotcha in Fortran that can lead to unintended behavior. Writing something like integer :: c=0 is a one-shot initialization, where subsequent calls of the function will actually remember the variable value if changed.

As a first pass at identifying possible issues, I am looking for one-shot declarations using:
grep -v "parameter" */*/*f90 | grep "::.*=" | grep -v pointer | grep -v save

These can be solved by adding an explicit save or parameter keyword when needed. Or, if the variable should not be saved, then set its value in a new line.

So far, I've just added some obvious parameter keywords. In the future we can detect possible issues with compiler flags, but just want to clean up obvious fixes first. There should not be an impact on the code results.


There is also the issue that 1_dp and 1.0_dp are not the same thing in Fortran (see: https://fortran-lang.org/learn/quickstart/gotchas/#floating-point-literal-constants-again). The former actually becomes a integer literal constant, and can have the wrong consequences if we are using them to compute real numbers. So I made a few changes in the code fixing these. It should not have an effect because the issue usually shows up when you are composing 2 of these integer literal constants, but is better practice to have the .0_dp added

@pmocz pmocz changed the title implicit save gotcha cleanup implicit save and floating point literal gotchas cleanup Sep 6, 2024
@pmocz pmocz changed the title implicit save and floating point literal gotchas cleanup implicit save and floating point literal gotchas Sep 6, 2024
@pmocz pmocz requested a review from warrickball as a code owner September 6, 2024 16:58
@pmocz pmocz self-assigned this Sep 6, 2024
@pmocz pmocz merged commit 9cd0805 into main Sep 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant