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

Assignment to an allocatable array in F2003

Andrew_Smith
Valued Contributor I
715 Views
In this example what array bounds would you expect for b ?

[bash]real a(4)
real, allocatable :: b(:)
integer i

do i = 1 to 4
   a(i) = float(i)
end do

b = a(3:4)
[/bash]
IVF gives bounds 3 to 4. It strikes me as wrong but I dont have a copy of the full standard.
0 Kudos
7 Replies
Steven_L_Intel1
Employee
715 Views
Well, the code you posted would not compile as it has syntax errors. It is not clear to me how you are determining that "IVF gives bounds 3 to 4". I will comment that, unless you compile with /assume:realloc_lhs, b will not get allocated according to the F2003 specs.
0 Kudos
abhimodak
New Contributor I
715 Views
Steve, I thought the same at first glance. The snippet above when compiled with /assume:realloc_lih gives 3 and 4. Without the /assume, I get 1 and 0 with IVF11.1065.

The 2003 handbook Adams et. al , Chapter 7, page 236 (and Metcalf et al 95/2003 explained, chapter 12, page 243) has the following for assignment of variable = expression ---

4. If the component is allocatable
a. if it is allocated, it is deallocated.
b. if the corresponding component of the expression is allocated, the variable
component is allocated with the same dynamic type and type parameters and,
if it is an array, with the same bounds. The value of the expression component
is then assigned to the variable component using defined assignment if there is
a consistent type-bound assignment available; otherwise, intrinsic assignment
is used.

Although it is mentioned in the context of the component of the derived type, it should be the same for intrinsic types as well.

I think then IVF is incorrectly (in the original post, I had typed "correctly"; hence edited with italics) giving the bounds when compiled with appropriate flag.

Abhi

p.s. For what it is worth, XLFortran version 11 is giving bounds 1 and 2. :(
0 Kudos
Steven_L_Intel1
Employee
715 Views
The code you posted does not compile - the syntax for the DO loop is incorrect. It's also incomplete. I corrected this and added code to view the bounds and can see that array B has bounds 3:4.

xlf is correct here - the bounds of the expression a(3:4) are 1:2. You can see this with the following test:

[fortran]real a(4)
real, allocatable :: b(:)
integer i

do i = 1 , 4
a(i) = float(i)
end do

b = a(3:4)

print *, b
print *, lbound(b), ubound(b)
print *, lbound(a(3:4)), ubound(a(3:4))
end[/fortran]

I will report this to the developers.
0 Kudos
abhimodak
New Contributor I
715 Views
Hi Steve

A loosely related topic of pointer remapping: (http://software.intel.com/en-us/forums/showthread.php?t=67515&o=a&s=lr).

Is this going to make it in August or later?

Abhi
0 Kudos
Steven_L_Intel1
Employee
715 Views
Issue ID is DPD200157905. Pointer remapping is expected to be in the end-of-year release.
0 Kudos
Andrew_Smith
Valued Contributor I
715 Views
Thanks Steve, sorry about the do loop syntax booboo.

Yes I did mean you to use /assume:realloc_lhs since we are testing F2003 conformance.

The problem showed up in a big project with array index checking on when I attempted to migrate to /assume:realloc_lhs for the whole project.
0 Kudos
Steven_L_Intel1
Employee
715 Views
The bug will be fixed in a future update.
0 Kudos
Reply