Array intrinsics with zero-size array argument

Quote:

> What are the array intrinsics SUM, DOT_PRODUCT,MATMUL supposed to

> return if one of the arguments is a zero-sized array, e.g. a(1:0)?

Besides the standard, one place to look is the

fortran 95 Handbook. On

p630 it says "The result of SUM (ARRAY) [...] has the value zero if

ARRAY has size zero and on p580 it says in similar language that

dot_product(x,y) = 0 if size(x) = size(y) = 0. On p599 it defines the

results of MATMUL using the SUM function and does not make exceptions

for arrays with zero-sized dimensions.

Thus the program

program xmatmul_zero_size

integer, parameter :: n1=2,n2=0,n3=3

integer :: imat(n1,n2),jmat(n2,n3)

imat = 0

jmat = 0

print*,shape(matmul(imat,jmat))

print*,matmul(imat,jmat)

end program xmatmul_zero_size

gives

2 3

0 0 0 0 0 0

on g95, gfortran, and Intel Visual Fortran.