Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran SAVE attribute with implicit type

I was trying to compile the following, and both gfortran and ifort reported a syntax error:

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

This is the gfortran -c test.f90 output:

allocatable, save :: A(:)
            1
Error: Invalid character in name at (1)

and the ifort -c test.f90 output:

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

Since both compilers report a syntax error, I wonder if this is a bug or not, or if someone knows what might have gone wrong?

like image 248
steabert Avatar asked Jun 17 '26 07:06

steabert


1 Answers

It is not a bug. From section 5.4.2 of the latest Fortran standard (or Metcalf, Reid and Cohen in more readable form), the allocatable statement may be used in the form:

allocatable [::] array-name [ (array-spec) ] [, array-name [ (array-spec) ]] ...

Thus, you have to use allocatable and save in separate statements. Both of the compilers that you used reported the error because they expected the array name after allocatable, but they encountered a comma.

like image 194
milancurcic Avatar answered Jun 18 '26 21:06

milancurcic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!