Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Out of array bounds question

jeraldlavassar
Beginner
1,499 Views
I have compiled an old mainframe program. To make it run successfully I was advised to turn off "array and string bounds" checking in the Runtime tab of Project Settings -->Fortran. I quote that suggestion, "On other programs that use one large array and pointers this compiler (CVF) will complain about going out of array bounds."

This prompted the question of what does the program do when it is instructed to write an array element that is out of the specified bounds. Does it just put it in an adjacent memory address to the kosher addresses for the array? If so, the original code must involve careful bookkeeping to assure that the address overwritten in going out of bounds is not accessed. At least the code should prevent that memory address(es) being read until it is appropriately overwritten.

Regards,

By one concerned, confused but thankful program generates same data as example programs





0 Kudos
4 Replies
james1
Beginner
1,499 Views
It used to be common to intentionally access array elements that were not defined. One example is say you have an array(N) then the programmer might access array(N+1) to find the end of the array. That is harmless, but not particularly structured of course.

When accessing array information that is out of bounds, and no bounds checking is present, you are simply creating an offset of the array at base address + size * index-1 and accessing that memory address. As long as the page in which that memory address is not protected against your desired mode of access, then the read (or write) will proceed silently. If you offset far enough you will find the memory address is in a memory page that is of an incompatible protection, resulting in a memory access violation.

You could always turn on bounds checking and fix what problems arise. :-)

James
0 Kudos
Steven_L_Intel1
Employee
1,499 Views
Another usage that was common a few decades ago, but still lives on, is the use of declaring an array argument in a subroutine as having bounds (1), where today you'd write (*). This depended on the general lack of array bounds checking at the time.

Steve
0 Kudos
Intel_C_Intel
Employee
1,499 Views
I must confess that I use to write code that intentionally went out of bounds. I had the following common statement:

Common/bsc/b(70,12),bc(70,8)

If I had a variable idx that had the value 1-12 to access the first array and 13-20 to access the second array then I could access the array:

b(i,idx)

When idx was 13-20 it would access the bc array as I intended.

A couple of years ago I took the time to rewrite this code. I believe it is more maintainable, and also it helps to have array bounds checking on to uncover errors.
0 Kudos
durisinm
Novice
1,499 Views
I inherited support of an application that uses negative array index values, and these arrays were not declared with negative lower bounds. The first element is a reference point, and the program accesses elements before and after that point as part of a memory management scheme. I cannot compile the program with array bounds checking on since it will stop execution.

I don't care for this scheme (especially since there is no systems documentation to give the big picture of how the memory is managed), but it works.

Mike
0 Kudos
Reply