# How to handle an array of structures when embedding Julia in C

**URL:** <https://discourse.julialang.org/t/how-to-handle-an-array-of-structures-when-embedding-julia-in-c/18661>\
**Category:** General Usage\
**Created:** [December 14, 2018, 3:51pm UTC](https://discourse.julialang.org/t/how-to-handle-an-array-of-structures-when-embedding-julia-in-c/18661 "2018-12-14T15:51:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [December 14, 2018, 3:51pm UTC](https://discourse.julialang.org/t/how-to-handle-an-array-of-structures-when-embedding-julia-in-c/18661/1 "2018-12-14T15:51:33Z")

</div>

Hi!

I have a function that returns an array of a structure. This function is called inside a C++ software using this code:

```nohighlight
    jl_value_t *filename = jl_eval_string("\"amz1.tle\"");
    jl_array_t *array_tle = (jl_array_t*)jl_call1(read_tle, filename);

```

It is working fine, since `jl_(tle)` shows all the elements in the Array. My question is, in C++, how can I obtain a pointer to each element of this array in which the type is `TLE` (a structure define in my package)?

I tried this:

```nohighlight
    jl_value_t* tle = (jl_value_t*)jl_array_data(array_tle);

```

but it gives me a segmentation fault.

I can make it work if data is `double`, `int`, etc. However, when the data is a structure, I have no idea how to handle inside C++ when unpacking from an array.

---

<div class="post-metadata">

**Author:** ![takieddine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/takieddine/32/38072_2.png) [@takieddine](https://discourse.julialang.org/u/takieddine)\
**Post date:** [January 19, 2023, 12:41pm UTC](https://discourse.julialang.org/t/how-to-handle-an-array-of-structures-when-embedding-julia-in-c/18661/2 "2023-01-19T12:41:40Z")

</div>

Have found a solution?

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [January 19, 2023, 7:07pm UTC](https://discourse.julialang.org/t/how-to-handle-an-array-of-structures-when-embedding-julia-in-c/18661/3 "2023-01-19T19:07:53Z")

</div>

No, I don’t! And I cannot even remember what was the work around 😃 Sorry. I think I create a Julia function to return the elements for me.
