# Procedure pointers and assumed-size arrays

**URL:** <https://fortran-lang.discourse.group/t/procedure-pointers-and-assumed-size-arrays/6713>\
**Category:** Help\
**Created:** [October 31, 2023, 12:58pm UTC](https://fortran-lang.discourse.group/t/procedure-pointers-and-assumed-size-arrays/6713 "2023-10-31T12:58:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [October 31, 2023, 12:58pm UTC](https://fortran-lang.discourse.group/t/procedure-pointers-and-assumed-size-arrays/6713/1 "2023-10-31T12:58:10Z")

</div>

We encountered a curious problem with procedure pointers and assumed-size arrays. The following code is accepted by Intel Fortran oneAPI but not by gfortran. Question is: is the code conforming or not?

```auto
! proc_assumed_size.f90 --
! Check problem with assumed size arrays in procedure pointer
!
module proc_pnt
    implicit none

    type proc
        procedure(), pointer, nopass :: p
    end type proc

contains

subroutine callit( p, array )
    type(proc), intent(in) :: p
    real, dimension(*), intent(in) :: array
    !real, dimension(:), intent(in) :: array <-- this is accepted by gfortran

    call p%p( array )
end subroutine callit
end module proc_pnt

module simple_proc
    implicit none

contains
subroutine mysub( array )
    real, dimension(*), intent(in) :: array

    write(*,*) array(1)
end subroutine mysub
end module simple_proc

program proc_assumed_size
    use proc_pnt
    use simple_proc

    implicit none

    type(proc) :: pp
    real :: array(10)

    call random_number( array )

    pp%p => mysub

    call pp%p( array )

end program proc_assumed_size

```

The error message from gfortran is:

```auto
proc_assumed_size.f90:17:14:

   17 | call p%p( array )
      | 1
Error: The upper bound in the last dimension must appear in the reference to the assumed size array 'array' at (1)

```

If I change the dummy argument in callit to be an assumed-shape array, both compilers are happy with the code.

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [October 31, 2023, 1:29pm UTC](https://fortran-lang.discourse.group/t/procedure-pointers-and-assumed-size-arrays/6713/2 "2023-10-31T13:29:11Z")

</div>

@arjen, nvfortran doesn’t give an error so I’m guessing its a bug in gfortran. I tried several mods to your code including adding an abstract interface for the procedure pointer but gfortran 13 always returned with your error. My abstract interface mod looks like

```auto
   abstract interface
      subroutine pf(array)
        real, intent(in) :: array(*)
      end subroutine pf
    end interface
    type proc
        procedure(pf), pointer, nopass :: p=>NULL()
    end type proc

```

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [October 31, 2023, 1:42pm UTC](https://fortran-lang.discourse.group/t/procedure-pointers-and-assumed-size-arrays/6713/3 "2023-10-31T13:42:59Z")

</div>

The NAG compiler accepts it as well. I believe it is standards conforming. It looks like gfortran has the characteristic of an argument to a procedure with an implicit interface backwards. If a procedure does not have an explicit interface it is assumed that an array argument is an assumed size array, not assumed shape. An assumed shape argument **would** need to know the upper bound but assumed size does not. That’s why gfortran accepts it when you change the interface of `callit`.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [October 31, 2023, 1:47pm UTC](https://fortran-lang.discourse.group/t/procedure-pointers-and-assumed-size-arrays/6713/4 "2023-10-31T13:47:09Z")

</div>

That is what I assumed as well. The code I am working with stems from way back and I recently converted it to use procedure pointers, As most if not all routines are contained in a module, changing callit to use assumed-shape is not a big problem, but it was puzzling.

Thanks everyone for the confirmation.
