When allocating zero-sized arrays in Fortran, I am getting counterintuitive behavior.
This code:
program test_zerosized
implicit none
integer, allocatable :: a(:),b(:)
allocate(a(0))
print *, ' a lower bound = ',lbound(a,1)
print *, ' a upper bound = ',ubound(a,1)
allocate(b(0:0))
print *, ' b lower bound = ',lbound(b,1)
print *, ' b upper bound = ',ubound(b,1)
return
end program test_zerosized
Produces the following output:
a lower bound = 1
a upper bound = 0
b lower bound = 0
b upper bound = 0
Is my compiler (gcc/gfortran 6.2.0) standard conforming? I don't get why lbound(a,1)==1
instead of lbound(a,1)==0
, since the total total array size is of zero elements. Thanks!