Often I want to write code that declares automatic arrays as follows:
subroutine foo(x)
real, intent(in) :: x(:)
integer :: n = size(x) ! not legal
real :: a(n),b(n),c(n) ! not legal
! real :: a(size(x)),b(size(x)),c(size(x)) ! legal but awkward
end subroutine foo
but gfortran says
size.f90:3:29:
3 | integer :: n = size(x)
| 1
Error: Assumed-shape array 'x' at (1) is not permitted in an initialization expression
size.f90:5:21:
5 | real :: a(size(x)),b(size(x)),c(size(x))
| 1
Error: Symbol 'a' at (1) already has basic type of REAL
size.f90:4:22:
4 | real :: a(n),b(n),c(n) ! not legal
| 1
Error: Variable 'n' cannot appear in the expression at (1)
Besides using the line I commented out, I know I can use ALLOCATABLE array, so that n = size(x)
can appear after the declarations and n can be used to allocate the arrrays. But would it make sense to extend Fortran so that the code above works? Often when I use the current syntax
real :: a(size(x)),b(size(x)),c(size(x))
I later define n = size(x)
anyway, and I wish I could have used n earlier to simplify the code.