[Fortran] NAG compiler requires to define variable before its usage
NAG compiler requires to define variable before its usage in type declaration section. For example, the following code is not correct:
subroutine test(a, n)
implicit none
real(8) :: a(n)
integer :: n
end subroutine test
since usage of n happens before actual type definition.
The proper code is:
subroutine test(a, n)
implicit none
integer :: n
real(8) :: a(n)
end subroutine test
Hi @foxtran,
Thanks for bringing this up!
Additionally, even if more permissive compilers accept the original code, the second form is significantly better in terms of readability. I think it's a good candidate for a new recommendation.
I'll leave this issue open so we don't lose sight of it. Naturally, feel free to submit a PR if you'd like to make a proposal! Below you will find a few tips. Otherwise, we'll note this idea and let you know of any relevant updates here.
Steps for adding a new recommendation (click me)
-
Each recommendation resides in its own directory under
Checks/. Create the directory and update the list of checks in theREADME.mdat the root of the repository. -
Add a
README.mdfile that includes the following:-
Title: ID (e.g., the next available
PWRnumber) + Name of the recommendation. - Issue: A brief description (1-2 sentences) of how the discouraged practice impacts the code.
- Actions: A brief explanation (1-2 sentences) of how to refactor the code from the discouraged to the encouraged practice.
- Relevance: A more detailed explanation of why adopting the recommended practice is beneficial, expanding on the previous points.
- Code examples: Include a before-and-after code example to illustrate the improvement.
- References: Add links or references for further reading, if available.
-
Title: ID (e.g., the next available
-
Create standalone
exampleandsolutionsource files containing the code examples. -
Optionally, include a benchmark demonstrating the before-and-after performance impact of the change. In cases like this, the expectation is that the performance of the code should not degrade.
For reference, feel free to check out previous PRs to see how these steps are implemented in practice. For example, this is the PR that added PWR075.
Naturally, don't hesitate to ask at any moment if you have any issues. We'll be glad to help!