Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29359 Discussions

variable scoping between subroutines

jvandeven
New Contributor I
804 Views

I have been developing a fortran program for around 6 years now, and haven'texperienced anyproblems in moving between different programme modules and subroutines. Recently, however, I have found that variables have fallen out of scope after returning from a pass to a subroutine. It is a basic question, but what do I need to do to ensure the integrety of variables during passes between subroutine calls?

Many thanks,

Justin.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
804 Views
When you say "fallen out of scope" do you mean that the values have been incorrectly changed? If so, that strongly suggests a coding error in the application. Variables do not "fall out of scope" within a routine. Usually a problem like this is caused by an argument type mismatch in the call or an out-of-bounds array reference in the called routine. It need not be with the variable in question.
0 Kudos
jvandeven
New Contributor I
804 Views

For example, a variable x (which is notreferenced by subroutine B) is equal to 5 before the call to subroutine B, and is equal to some random number, or identified as an undefined pointer array after the call to subroutine B. I will check mycode forinaccurate array referencing and variable definitions.

Many thanks,

Justin

0 Kudos
Steven_L_Intel1
Employee
804 Views
The Intel compiler has options that can help. Generated interface checking (/gen-interface /warn:interface) and array bounds checking (/check:bounds).
0 Kudos
jvandeven
New Contributor I
804 Views

Brilliant - I've found one bug, and suspect that there is another. I will try the compiler options that you suggest and continue to track them down. You have reduced by stress levels considerably (I was starting to wonder whether I had misunderstood use of modules and subroutines at a fundamental level).

Best regards,

Justin.

0 Kudos
Reply