- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(:) 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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page