# How to find the number of elements in a pointer to array from C?

**URL:** <https://discourse.julialang.org/t/how-to-find-the-number-of-elements-in-a-pointer-to-array-from-c/21195>\
**Category:** General Usage\
**Created:** [February 26, 2019, 12:45am UTC](https://discourse.julialang.org/t/how-to-find-the-number-of-elements-in-a-pointer-to-array-from-c/21195 "2019-02-26T00:45:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [February 26, 2019, 12:45am UTC](https://discourse.julialang.org/t/how-to-find-the-number-of-elements-in-a-pointer-to-array-from-c/21195/1 "2019-02-26T00:45:12Z")

</div>

```julia
julia> D = GMT.ogrfeatures2GMTdataset(colomb);
ERROR: BoundsError: attempt to access 119-element Array{GMT.GMTdataset,1} at index [127]

```

The thing happens at an instruction like this `unsafe_wrap(Array, x, np)` and is cause by a wrong `np` but the whole thing comes from wrapping a C lib and fixing it implies find/fix the bug in the C side. However, Julia knows the size of `x` because it says there are 119-elements in it. So, how can I access to the same information? This would allow to solve the issue for now.

Thanks.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [February 26, 2019, 1:13am UTC](https://discourse.julialang.org/t/how-to-find-the-number-of-elements-in-a-pointer-to-array-from-c/21195/2 "2019-02-26T01:13:04Z")

</div>

Sorry, my confusion. The error come from another line.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 26, 2019, 1:25am UTC](https://discourse.julialang.org/t/how-to-find-the-number-of-elements-in-a-pointer-to-array-from-c/21195/3 "2019-02-26T01:25:50Z")

</div>

Try to answer the question:

> <https://github.com/JuliaInterop/Clang.jl/blob/289bdd510317307a7999ad7696e531ef0229944e/src/type.jl#L219-L220>

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [February 26, 2019, 1:34am UTC](https://discourse.julialang.org/t/how-to-find-the-number-of-elements-in-a-pointer-to-array-from-c/21195/4 "2019-02-26T01:34:47Z")

</div>

Thanks, that `clang_getNumElements()` seem that could be a good lead. But I was no clear in my second post. It turns out that the error doesn’t come from the `unsafe_wrap()` call but from an error in my julia code (now fixed).
