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

Arrays

Intel_C_Intel
Employee
310 Views
In the code below FillArray2 doesn't work. Why is A(*) equivalent to A(1:*) but not equivalent to A(:)?
Code:
!------------------------------------------------------------------------------

PROGRAM TestArray

!------------------------------------------------------------------------------

	IMPLICIT NONE

	!----------
	! Variables
	!----------

	INTEGER*4, ALLOCATABLE :: Array1(:)
	INTEGER*4, ALLOCATABLE :: Array2(:)

	!------------------
	! Body of TestArray
	!------------------

	ALLOCATE(Array1(5))
	ALLOCATE(Array2(5))

	Array1 = 0
	Array2 = 0

	CALL FillArray1(Array1)

	CALL FillArray2(Array2)

	DEALLOCATE(Array1)
	DEALLOCATE(Array2)

!------------------------------------------------------------------------------

END PROGRAM TestArray

!------------------------------------------------------------------------------

SUBROUTINE FillArray1(Arr1)

	INTEGER*4, INTENT(INOUT) :: Arr1(*)
	INTEGER*4 nCount

	DO nCount = 1, 5
		Arr1(nCount) = nCount
	END DO

RETURN
END

!------------------------------------------------------------------------------

SUBROUTINE FillArray2(Arr2)

	INTEGER*4, INTENT(INOUT) :: Arr2(:)
	INTEGER*4 nCount

	DO nCount = 1, 5
		Arr2(nCount) = nCount + 10
	END DO

RETURN
END
0 Kudos
1 Reply
Steven_L_Intel1
Employee
310 Views
(:) in an argument is a different beast called "assumed shape" and requires extra information to be passed by the caller (a descriptor) and an explicit interface is required. (*) and (1:*) is "assumed size" where the upper-bound is not provided and the program is required to make sure that it does not index outside of the passed-in array elements.
0 Kudos
Reply