I am wondering whether this is legal or not according to the standard, i.e. passing an array to a subroutine with a small size without an explicit slice.
Neither gfortran -Wall -pedantic -fbounds-check
nor valgrind
show any error, but I am not sure that providing the actual slice would be needed.
subroutine foobar(x,n)
implicit none
integer, intent(in) :: n
integer, intent(in) :: x(n)
integer :: i
write(*,*) "foobar"
do i = 1, n
write(*,*) i, x(i)
end do
end subroutine foobar
program main
implicit none
integer, parameter :: s = 5
integer :: dat(s)
integer :: i
interface
subroutine foobar(x,n)
implicit none
integer, intent(in) :: n
integer, intent(in) :: x(n)
end subroutine foobar
end interface
dat = [10,20,30,40,50]
write(*,*) "main"
do i = 1, s
write(*,*) i, dat(i)
end do
call foobar(dat,s) ! OK since actual size
call foobar(dat(4:),2) ! OK since slice has 2 positions
call foobar(dat,2) ! ?? smaller size
call foobar(dat(4),2) ! ?? giving only start position
end program main