- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recently ran into an issue with assignment of incompatible array sections to an allocatable array that was not caught by the Intel Fortran compiler's bounds checking. A reduced example is:
subroutine sub1(array) implicit none real, intent(inout) :: array(42) real, allocatable :: send(:) allocate(send(1)) send(:) = array(9:10) end subroutine ! subroutine sub2(array) ! implicit none ! ! real, intent(inout) :: array(42) ! real :: send(1) ! ! send(:) = array(9:10) ! end subroutine program bug implicit none real :: array(42) array = 0.0 call sub1(array) ! call sub2(array) end program
Subroutines sub1 and sub2 assign an array section of size two into an array section of size one. Obviously, this is illegal. The version in sub2, which assigns to an ordinary array, is diagnosed at compile time when bounds checking is on. The version in sub1, which assigns to an allocatable array, is not caught at compile time or at run time.
Is this the expected behavior? If so, are the capabilities and/or limitations of Intel Fortran's array bounds checking documented anywhere?
This result was obtained with Intel Fortran 15.0.1 20141022 on Mac OS X 10.10.1.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're asking for "shape checking", which we don't do. Sometimes bounds checking will spot problems on assignment, but not always.
I will note that if you compile with -standard-semantics and remove the (:) from the references to send, then sub1 will work correctly as send will get automatically reallocated to the correct shape. You shouldn't use (:) unless you explicitly want to disable the standard's automatic reallocation feature. (See https://software.intel.com/en-us/blogs/2008/03/31/doctor-it-hurts-when-i-do-this)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page