Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

Bounds checking, zero sized array and sequence association

$
0
0

I work on code that frequently relies on sequence association when passing arrays as arguments. Zero sized arrays are not a problem during program execution but when I turn on bounds checking there doesn't seem to be any way to have a valid index for the actual array argument.

This example shows a simple version where array(0) and array(1) are both out of bounds access. Of course, I could just pass the whole array instead of relying on sequence association, but in many cases the sequence association is a way to pass array sections and it's not possible to find a method that works with bounds checking for both zero sized arrays and non-zero sized arrays. Is there any way to enable bounds checking that "works" in this situation? ("works" = does what I want it to, not what I tell it to)

program zero

  integer,parameter :: array_dim=0
  integer :: array(array_dim)

  array=1

  call print_array(array(0),array_dim)

END PROGRAM zero

subroutine print_array(array,size)
  integer :: array(*),size
  integer :: i

  do i=1,size
    write(*,*)i,array(i)
  end do

end subroutine print_array

 


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>