Consider an intrinsic assignment statement where the left-hand side is not allocated and is an array:
variable = expr
In such a case, the array variable
is allocated to the shape of the expression expr
, with lower bound equal to the value of LBOUND(expr)
(see Fortran 2018 10.2.1.3).
For the example of the question
c = b - a
the right-hand side is the expression b-a
. For this expression LBOUND(b-a)
is equal to 1: b-a
is not a whole array (F2018 16.9.109). The lower bound of c
on allocation is thus 1.
The only way the variable assigned to in intrinsic assignment with allocation to have lower bound not 1 is for the right-hand side to have lower bound not 1. In the assignment (c
not allocated)
c = b
then c
has lower bound that of b
.
You could avoid an explicit allocate statement with
c = b
c = c - a
but that is rather unclear and (to repeat a point in Vladimir F's answer) would you want the lower bound to be that of b
or a
if these differ.
For completeness:
allocate(c(7:17), source=b-a)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…