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

Swap as Array(1:2)

mattsdad
Beginner
334 Views

I just came across a curious capability of Fortran in a manual.

Is it true that in Fortran an array can be assigned to itself in reverse order as in:

INTEGER, PARAMETER :: max = ...

REAL ::A(max)

... initialzation of data in A ...

A(1 : max) = A(max : 1 : -1)

without any form of temporary being used?

0 Kudos
1 Reply
Steven_L_Intel1
Employee
334 Views

Yes, because the language semantics mean that the compiler creates a temporary for you. Then the compiler tries to figure out if the temporary can be eliminated, which in this case it probably isn't.

In essence, array assignment completely evaluates the right-hand-side of the assignment before assigning to the left-hand-side.

0 Kudos
Reply