# Correct way to ccall a Fortran subroutine requiring pointers

**URL:** <https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191>\
**Category:** General Usage\
**Tags:** fortran\
**Created:** [May 2, 2023, 10:57am UTC](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191 "2023-05-02T10:57:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 2, 2023, 11:16am UTC](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191/2 "2023-05-02T11:16:42Z")

</div>

I think the answer to your general question is this one: [Calling Fortran variables from Julia - #3 by anowacki](https://discourse.julialang.org/t/calling-fortran-variables-from-julia/27293/3)

> [@lucifer1004](#):
>
> Julia corresponds to `B(2:3, 3:6)` in Fortran, is it always true that indices will start from 1 at the Julia side?

Note that this is not specific of julia, but of the interface. Since you pass a reference, one side does not know about how the indexing was at the other side:

```fortran
program main
    integer :: i, a(3), b
    do i = 1,3
        a(i) = i
    end do
    print *, a
    call test(a(2:3),b)
    print *, b
end

subroutine test(a,b)
    integer :: a(2), b
    b = a(1)
end

```

Will print:

```julia
           1 2 3
           2

```

which means that `b` assumed the value of what was `a(2)` in the main program.

You can, in Julia, use `OffsetArrays` to use arbitrary indexing (but then you need one additional layer of care in passing the array to fortran, since an `OffsetArray` is an array contained in a struct that carries the information about the offsets.

---

_[View the full topic](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191)._
