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

## Passing Vector Segments to Assumed-sized Array

New Contributor II
477 Views

Hello,

I working some inhereted code that uses assumed-size arrays. I haven't worked with assumed-size assays before (I'm under the impression that assumed-shaped are preferrable and assumed-size only exist for backward compatibility) and the way they are used doesn't seem to fit neatly into the documentation I have found online about assumed-size arrays. What seems strange to me is that the main program has one long vector and single elements of this vector are passed into assumed-size array interface parameters of a subroutine. The ones of these that are of the format a(*)  get created as vectors of length 1 but the ones that are of the form a(10,*) get created as arrays of shape (10,1). At least that is my understanding of how it behaves from reverse enginerring the  code. So my question is, have I understod correctly and can I rely one the code to consitently behave this way? To make the question clear here is a code snippet

```    program test
real ::X(100), y(5)

call sub(x(1),x(10),x(50),y)

contains
subroutine sub(a,b,c)
real:: a(*), b(10,*), c(*), d(*)

end subroutine sub
end program test```

So in this example I a and c are of shape (1), b is of shape (10,1) and d is of shape (5). I've seen documentation explaining why d would be (5) but not confirming b should always be (10,1).

1 Solution
Honored Contributor III
477 Views

The extent of the last dimension of a,b,c and d are, technically, 100, 9, 51, 5, but there's no way to determine that in the program. Passing a single element to an assumed-size array is called "sequence association", and the dummy argument (a,b,c,d) is associated with the remainder of the extent of the actual argument. (b is a bit strange - as there is actually one more element left over. Your example would have been easier to explain if the subscripts were 11 and 51.)

In pre-F77 days, it was popular to declare dummy arrays with a last bound of 1, relying on the lack of bounds checking in most early compilers. F77 added assumed-size arrays which replace the (1) hack.

Here's what the standard says (8.5.8.5):

The size of an assumed-size array is determined as follows.
• If the effective argument associated with the assumed-size dummy array is an array of any type other than default character, the size is that of the effective argument.
• If the actual argument corresponding to the assumed-size dummy array is an array element of any type other than default character with a subscript order value of r (9.5.3.2) in an array of size x, the size of the dummy array is x − r + 1.
• If the actual argument is a default character array, default character array element, or a default character array element substring (9.4.1), and if it begins at character storage unit t of an array with c character storage units, the size of the dummy array is MAX (INT ((c − t + 1)/e), 0), where e is the length of an element in the dummy character array.
• If the actual argument is a default character scalar that is not an array element or array element substring designator, the size of the dummy array is MAX (INT (l/e), 0), where e is the length of an element in the dummy character array and l is the length of the actual argument.

3 Replies
Honored Contributor III
478 Views

The extent of the last dimension of a,b,c and d are, technically, 100, 9, 51, 5, but there's no way to determine that in the program. Passing a single element to an assumed-size array is called "sequence association", and the dummy argument (a,b,c,d) is associated with the remainder of the extent of the actual argument. (b is a bit strange - as there is actually one more element left over. Your example would have been easier to explain if the subscripts were 11 and 51.)

In pre-F77 days, it was popular to declare dummy arrays with a last bound of 1, relying on the lack of bounds checking in most early compilers. F77 added assumed-size arrays which replace the (1) hack.

Here's what the standard says (8.5.8.5):

The size of an assumed-size array is determined as follows.
• If the effective argument associated with the assumed-size dummy array is an array of any type other than default character, the size is that of the effective argument.
• If the actual argument corresponding to the assumed-size dummy array is an array element of any type other than default character with a subscript order value of r (9.5.3.2) in an array of size x, the size of the dummy array is x − r + 1.
• If the actual argument is a default character array, default character array element, or a default character array element substring (9.4.1), and if it begins at character storage unit t of an array with c character storage units, the size of the dummy array is MAX (INT ((c − t + 1)/e), 0), where e is the length of an element in the dummy character array.
• If the actual argument is a default character scalar that is not an array element or array element substring designator, the size of the dummy array is MAX (INT (l/e), 0), where e is the length of an element in the dummy character array and l is the length of the actual argument.

New Contributor II
477 Views

Thanks you! That is really helpful and very different from what I had inferred from how the assumed-size arrays get presented in the debugger

Honored Contributor III
477 Views

The debugger shows them as (1) because it has no information about the actual bounds.