A question on the Fortran newsgroup started a discussion on what is and is not allowed syntax for setting lower bounds on an allocatable array, and how that would be affected by the LHS using X(:)= versus X= and we disagreed even after reading the 2018 standard so we “asked the compilers” and got three different results with three compilers :>. At least we are not the only ones confused. Wondering if anyone agrees or disagrees with the following minimal code being standard (f2018) and what the results should be. The idea is how you can change the lower bound to a value other than one
on an allocatable array and when or if the lower bound gets reset on an assignment:
program testit
integer, allocatable :: X(:)
integer,dimension(-2:2) :: b, c
integer :: isize
! allocate it
isize=size(b)+size(c)
allocate(x(0:isize-1))
x(:)=[b,c]; call show()
x=[b,c]; call show()
! what should it change to?
x(:)=[11,22,33]; call show()
x=[1,2,3]; call show()
x(1:)=[10,20]; call show()
!oops -- apparently not legal but wish it was (thought it was -- need to look this one up).
!X=[integer,dimension(0:isize-1) :: b,c]; call show()
contains
subroutine show()
write(*,gen)X,'bounds',lbound(x),ubound(x)
end subroutine show
end program testit
typing this not pasting it, so forgive any inadvertent syntax errors. What I hope to have typed compiled and ran without warning on all the compilers with default flags (at least).
should not change that, but the next x= keeps it the same size and type. One compiler changed LBOUND to 1, another left it at 0. Another left it at 0 on this one, but when the size changed it to 1; but the other one that left it at 0 left it at 0 again. So I agree that the first x(:)= should leave it at 0; after seeing the compiler results not sure when the size and type is not changed in the first x=. At least at first glance, it seemed one compiler left it at 0 once set in the allocate() until explicitly deallocated; another left it at 0 unless the size changed, the other changed it to 1 on the first X= even though type and size had not changed. So it the LBOUND should have changed on the first x= ?