- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was trying to compile the following piece of code:
module test
implicit real*8 (a-h,o-z)
allocatable, save :: A(:)
end module test
for which ifort gave the following error:
test.f90(3): error #5277: Syntax error, found ',' following statement keyword
allocatable, save :: A(:)
------------^ test.f90(3): error #5082: Syntax error, found '::' when expecting one of: ( , <END-OF-STATEMENT> ; [
allocatable, save :: A(:)
------------------^ compilation aborted for test.f90 (code 1)
However, without the save attribute, or by adding an explicit type, it compiles fine:
module test
implicit real*8 (a-h,o-z)
allocatable :: A(:)
end module test
module test
implicit real*8 (a-h,o-z)
real*8, allocatable, save :: A(:)
end module test
Is it not allowed to use the save attribute like that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The ALLOCATABLE statement, like all of the "attribute specification statements", doesn't allow you to specify additional attributes. If you want to use any of the "attribute specification statements", you may specify only one attribute on that statement.
If you want to use a comma list, then use a type declaration statement such as REAL or INTEGER.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The ALLOCATABLE statement, like all of the "attribute specification statements", doesn't allow you to specify additional attributes. If you want to use any of the "attribute specification statements", you may specify only one attribute on that statement.
If you want to use a comma list, then use a type declaration statement such as REAL or INTEGER.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steven, you may also specify the SAVE attribute in a separate statement, if you wish.
[fortran]
module test
implicit real*8 (a-h,o-z)
allocatable :: A(:), B(:)
save :: A, B, C
end module test[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using SAVE in a module data section is superfluous. Using SAVE on an allocatable array in a subroutine or function can be desireable when you do not know the size of the data until first call (where you once only allocate) and you want it to persist across calls. Mecej4's suggestion is a work around, though I would not use in in module data (not necessary there).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In previous versions of the Fortran standard SAVE in a module could, theoretically, be useful if you had an implementation that didn't treat module variables as always SAVE. Fortran 2003 or maybe 2008 codified this so it is no longer needed, but it doesn't hurt either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:
In previous versions of the Fortran standard SAVE in a module could, theoretically, be useful if you had an implementation that didn't treat module variables as always SAVE. Fortran 2003 or maybe 2008 codified this so it is no longer needed, but it doesn't hurt either.
Does this mean, in some prior versions, modual variables lay in the scope of where individual USE statements occure? IOW USE equiv to INCLUDE
How odd.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Prior to F2003, I think, if you didn't say SAVE on module variables, they became undefined if that module was not USEd in any active call tree. This is similar to the way COMMON was defined in the past, allowing for "overlay" implementations. The standards committee had a burst of sanity and decided to make module variables implicitly SAVE, at the same time as variables with initialization were also made implicitly SAVE. Practically speaking, though, this had no effect - I don't know of a single implementation that didn't treat module variables as SAVE already.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page