Does that code respect the standard about conformable arrays

When I compile this program with 4 differents compilers

program conform
  implicit none
  integer :: i
  character(32) :: var_format
  integer, allocatable :: a(:,:), b(:,:), c(:,:)
  a = reshape([(i,i=1,9)], [3,3])
  b = reshape([1,2,3], [1,3])
  c = a - b
  write(var_format,"(a,i0,a,i0,a)") "(",size(c,1), "(", size(c, 2), "(i0,1x)/)))"
  print var_format, c
end program conform

I found most of the time (for 3 compilers)
0 0 0
2 2 6
4 8 9
and for the last compiler (it seems that only the first line what substracted)
0 0 0
4 5 6
7 8 9

But if I quote the section 3.11 of Metcalf et all about Array expressions
“two arrays of the same shape are said to be conformable and a scalar is conformable with any array”
So it seems that this expression is not valid because the two arrays have not the same shape, despite of 3 compilers give the same result. Could anybody confirm that behavior or explain why the first 3 compilers give the same results ?
Bests

The sizes of the two tables, a and b are not the same (9 and 3), therefore, a-b is not correct.
If you compile your code with options to check the table bound at runtime, you’ll get an error.

Try the compilation with:

gfortran -Og -g -fbacktrace -fcheck=all

Then, run it you’ll get this error:

At line 8 of file a.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array ‘b’ (1/3)

Welcome to the forum!

As @gardhor already wrote, the two arrays do not conform and if you use the array bound checking option of your compiler you should get an error.

1 Like

Thanks I wanted to be sure that is illegal!

Perhaps all compilers should display the following text:

“In cases where there is no interpretation of your program according to the Standard, the compiler will attempt to read your mind and make you happy. This has never worked. Alternatively, study https://wg5-fortran.org/N2201-N2250/N2221.pdf