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

Option to keep variables defined

Peter12367
Beginner
453 Views

Dear all,

is there an option in Intel Fortran that ensures that variables in a subroutine retain their value when the subroutine is exited? I have not been able to find it so far.

Best

Peter

0 Kudos
4 Replies
GVautier
New Contributor III
430 Views

Hi
I think that Qsave will do the job https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2025-1/save-qsave.html

Beware that it's an atomic bomb that will apply to every variable everywhere in your program. It could be better to explicitly save only variables when required with the option save in declarations.

0 Kudos
DavidWhite
Valued Contributor II
381 Views
0 Kudos
Steve_Lionel
Honored Contributor III
367 Views

I would strongly recommend using SAVE rather than an option. Figure out which variables need to be kept defined and give them the SAVE attribute. If you're asking this, make sure you are not also assuming that variables are preset to zero.

0 Kudos
DavidWhite
Valued Contributor II
349 Views

To make Steve's comment absolutely clear -- in Fortran, all variables are undefined unless initiailised -- so don't assume a variable that has not been initialised has a value of zero.

0 Kudos
Reply