next up previous contents index
Next: Array Sections Up: Arrays as Arguments Previous: Adjustable Arrays

Assumed-size Arrays

    There may be circumstances in which it is impracticable to use either fixed or adjustable array declarations in a procedure because the actual size of the array is unknown when the procedure starts executing. In this case an assumed-size array is a viable alternative. These are also only permitted for dummy argument arrays of procedures, but here the array is, effectively, declared to be of unknown or indefinite size. For example:
 
       REAL FUNCTION ADDTWO(TABLE, ANGLE)  
       REAL TABLE(*) 
       N = MAX(1, NINT(SIN(ANGLE) * 500.0)) 
       ADDTWO = TABLE(N) + TABLE(N+1) 
       END
Here the procedure only knows that array TABLE is one-dimensional with a lower-bound of one: that is all it needs to know to access the appropriate elements N and N+1. In executing the procedure it is our responsibility to ensure that the value of ANGLE will never result in an array subscript which is out of range. This is always a danger with assumed-size arrays. Because the compiler does not have any information about the upper-bound of an assumed-size array it cannot use any array-bound checking code even if it is normally able to do this. An assumed-size array can only have the upper-bound of its last dimension specified by an asterisk, all the other bounds (if any) must conform to the normal rules (or be adjustable using integer arguments).

An assumed size dummy argument array is specified with an asterisk as the upper bound of its last (or only) dimension. All the other dimension bounds, if any, must conform to normal rules for local arrays or adjustable arrays.

There is one important restriction on assumed size arrays: they cannot be used without subscripts in I/O statements, for example in the input list of a READ statement or the output list of a WRITE statement. This is because the compiler has no information about the total size of the array when compiling the procedure.


next up previous contents index
Next: Array Sections Up: Arrays as Arguments Previous: Adjustable Arrays
Helen Rowlands
8/27/1998