- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am compiling a large code that expects to be able to send a slice of an array pointerinto a subroutine. See simple example attached.
[vb]real, pointer :: a(:) ! allocate, assign a, etc., then call sub(a(4), 3) [/vb]
with the intent of sending an array of 3 values starting at a(4) into the subroutine.
Compiler is giving me this error:
error #7836: If the actual argument is scalar, the corresponding dummy argument shall be scalar unless the actual argument is an element of an array that is not an assumed-shape or pointer array, or a substring of such an element.
However, if I create an array slice it works fine
[cpp]real, pointer :: tmp(:) tmp => a(4:6) call sub(tmp, 3) [/cpp]
Is this a bug or a feature?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feature - of the Fortran language. You are trying to use "sequence association" but that is not available for POINTER arrays because pointers can point to discontiguous memory. Make the array ALLOCATABLE instead and it will work.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp] program TestCompiler implicit none integer :: i real, pointer :: a(:), tmp(:) allocate(a(10)) do i = 1,10 a(i) = i enddo print *, a ! pause read(5,*) i ! fails ! call sub(a(4),3) ! ! works tmp => a(4:6) call sub(tmp,3) ! pause read(5,*) i contains subroutine sub(x,n) integer :: n real :: x(n) print *, x end subroutine sub end program TestCompiler [/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feature - of the Fortran language. You are trying to use "sequence association" but that is not available for POINTER arrays because pointers can point to discontiguous memory. Make the array ALLOCATABLE instead and it will work.

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