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

SAVE attribute seems to fail when used with implicit type

Steven_V_
Beginner
1,618 Views

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?

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,618 Views

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.

View solution in original post

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,619 Views

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.

0 Kudos
mecej4
Honored Contributor III
1,618 Views

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]

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,618 Views

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

0 Kudos
Steven_L_Intel1
Employee
1,618 Views

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.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,618 Views

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

0 Kudos
Steven_L_Intel1
Employee
1,618 Views

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.

0 Kudos
Reply