Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

Passing slice of array pointer to sub

csh1
Beginner
1,827 Views

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. C:\HTC\TestBench\TestCompiler\TestCompiler\TestCompiler.f9033

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?

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,827 Views

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.

View solution in original post

0 Kudos
2 Replies
csh1
Beginner
1,827 Views
I tried to add the example source file but it didn't show up in my post. Here it is
[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]

0 Kudos
Steven_L_Intel1
Employee
1,828 Views

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.

0 Kudos
Reply