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).