Okay, so yesterday I had a co-worker coming into my office and asking me a question about Fortran code that he had to work with.
Basically, the code that he works with has a long, multidimensional array, and a subroutine that expects just this long, multidimensional array as a parameter.
However, the code calling that subroutine only passes the first element of the array. Yet the code works. So he asked me how that could be.
I haven't seen his particular code, but here's an example how I understand the issue (and it works!):
subroutine print_array(a)
implicit none
integer :: a(10)
write(*, *) a
end subroutine print_array
program passing
implicit none
integer :: i(10)
i = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /)
call print_array(i(1))
end program passing
So I told him that Fortran stores arrays sequentially, and the location of the array is the same as to the first element, and since the subroutine expects a certain shape, it knows how far to read along this sequence, and so on.
I also told him that this was bad programming practice and that he shouldn't write this kind of code himself.
But since then I have been wondering: Why did whoever wrote this do it this way in the first place? Is there any reason to do that? (It doesn't even have to be a good reason.)
Or am I right and this is just silly and far too error-prone?