- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I noticed different behavior of allocatable arrays defined in a subroutine or function between CVF and IVF. In CVF a local allocatable array is automatically deallocated upon exit from the routine unless it was declared with a 'save' attribute. However in IVF the array remains allocated. Is this down to a change in standard or is it controlled by a compiler setting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. /Qsave says to make all local variables SAVE and it is doing that. If that is not what you want, then don't use that switch (which I consider a Band-Aid for incorrect code.)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just based on what you wrote, I'd have to say you are mistaken in your observation. The standard says that local ALLOCATABLE arrays, if they do not have the SAVE attribute, are automatically deallocated on exit and Intel Fortran does that. If you have an example showing otherwise I'd like to see it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just based on what you wrote, I'd have to say you are mistaken in your observation. The standard says that local ALLOCATABLE arrays, if they do not have the SAVE attribute, are automatically deallocated on exit and Intel Fortran does that. If you have an example showing otherwise I'd like to see it.
Hi Steve,
I have the All variables SAVE/QSave set but from your reply this directive should not affect the allocatable array. I have to deallocate the array before allocating it again.
When I turn the "All variables SAVE/QSave" directive off the array is deallocatedas expected.
IsQSave supposed to behave like this with respect to allocatable arrays?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. /Qsave says to make all local variables SAVE and it is doing that. If that is not what you want, then don't use that switch (which I consider a Band-Aid for incorrect code.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. /Qsave says to make all local variables SAVE and it is doing that. If that is not what you want, then don't use that switch (which I consider a Band-Aid for incorrect code.)
Thanks Steve,
You answered my original question regarding the QSave switch. I agree with your approach and I'm using the save attribute only where required in new code. The problem arose because during the project conversion from CVF to IVF the QSave attribute was automatically set up because CVF did not conform to the standard by assuming all variables (except allocatable) are saved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CVF conformed to the standard - your program did not. The standard, in most cases, specifies the rules for a standard-conforming program. A program that does not conform to the standard - for example, it references a non-SAVEd variable before definition, could do anything. CVF's behavior to apply assumed SAVE semantics to non-allocatable variables is an extension, but is allowed by the standard.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page