SAVE attribute seems to fail when used with implicit type

SAVE attribute seems to fail when used with implicit type

Bild des Benutzers Steven V.

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?

7 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Steve Lionel (Intel)
Best Reply

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.

Steve
Bild des Benutzers mecej4

Steven, you may also specify the SAVE attribute in a separate statement, if you wish.

module test
implicit real*8 (a-h,o-z)
allocatable :: A(:), B(:)
save :: A, B, C
end module test

Bild des Benutzers jimdempseyatthecove

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

www.quickthreadprogramming.com
Bild des Benutzers Steve Lionel (Intel)

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.

Steve
Bild des Benutzers jimdempseyatthecove

Quote:

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

www.quickthreadprogramming.com
Bild des Benutzers Steve Lionel (Intel)

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.

Steve

Melden Sie sich an, um einen Kommentar zu hinterlassen.