# How to \`unsafe\_wrap()\` with array of struct?

**URL:** <https://discourse.julialang.org/t/how-to-unsafe-wrap-with-array-of-struct/76952>\
**Category:** General Usage\
**Tags:** question, ccall\
**Created:** [February 23, 2022, 3:32am UTC](https://discourse.julialang.org/t/how-to-unsafe-wrap-with-array-of-struct/76952 "2022-02-23T03:32:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [February 23, 2022, 3:32am UTC](https://discourse.julialang.org/t/how-to-unsafe-wrap-with-array-of-struct/76952/1 "2022-02-23T03:32:48Z")

</div>

I have C code that returns an array of struct using pointer:

```julia
mutable struct Result
    value :: Cdouble
    len_sequence :: Cint # length of sequence[]
    sequence :: Ptr{Cint}
end

mutable struct ResultList
    len_list :: Cint # length of list[]
    list :: Ptr{Result}
end

```

Basically, `ResultList` is a vector of `Result`.

After `ccall()`, I have `result_list :: ResultList` on hand. The following works:

```julia
# result_list :: ResultList
for i in 1:result_list.len_list
    result = unsafe_load(result_list.list, i) # result :: Result
    seq = unsafe_wrap(Vector{Cint}, result.sequence, result.len_sequence) # seq :: Vector{Cint}
    @show seq # works as intended
end

```

But the following produces segfault:

```julia
unsafe_wrap(Array, result_list.list, result_list.len_list)

```

What am I doing wrong? Is it not possible to use `unsafe_wrap()` in this case?
