# Unboxing while embedding Julia in C++?

**URL:** <https://discourse.julialang.org/t/unboxing-while-embedding-julia-in-c/37491>\
**Category:** General Usage\
**Created:** [April 13, 2020, 7:07am UTC](https://discourse.julialang.org/t/unboxing-while-embedding-julia-in-c/37491 "2020-04-13T07:07:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 13, 2020, 7:07am UTC](https://discourse.julialang.org/t/unboxing-while-embedding-julia-in-c/37491/1 "2020-04-13T07:07:29Z")

</div>

Hello!

So I am embedding some Julia code in C++, and this Julia code returns;

```julia
2×2 Array{Array{Int64,1},2}:
 [2812, 2126, 74, 1469, 892, 1881, 1693, 318, 1337, 2805 … 2742, 1390, 1916, 2307, 1110, 6, 856, 2408, 2786, 218] … [1760, 1090, 2381, 2376, 1265, 905, 1461, 2351, 1273, 880 … 618, 2298, 321, 420, 1035, 1042, 1717, 2180, 2440, 1473]
 [1704, 29, 2564, 176, 2420, 1481, 1124, 2284, 2597, 1442 … 2488, 2475, 2260, 2151, 1366, 341, 2772, 2432, 2346, 2224] [306, 1316, 2111, 1333, 1671, 1131, 2553, 1662, 2308, 2502 … 632, 1140, 2417, 186, 1535, 1038, 1241, 2055, 322, 2663]

```

I am trying then to return it in a way so that I can use it in my C++ application, but I have some trouble doing this since it is an array of an array, which I cannot figure out from this documention of how to do, [Embedding Julia · The Julia Language](https://docs.julialang.org/en/v1/manual/embedding/). I can construct the inner array as:

```julia
jl_value_t *innerarray_type = jl_apply_array_type((jl_value_t*)jl_int64_type, 1);

```

But cannot figure out how to construct the outer array, which consists of the inner array.

Secondly, I have found a function which supposedly should return the type given as;

```julia
jl_typeof()

```

But again I have trouble unboxing this properly. Can anyone point me in the right direction?

Kind regards

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 14, 2020, 5:31am UTC](https://discourse.julialang.org/t/unboxing-while-embedding-julia-in-c/37491/2 "2020-04-14T05:31:22Z")

</div>

I will post my personal solution. I ended up changing the array to:

```julia
4x1 Array{Array{Int64,1},1}:

```

And then the following code would work:

```julia
    jl_function_t *RangeList = jl_get_function(modJulia,"RangeSearch");

    jl_array_t *retRL = (jl_array_t *)jl_call2(RangeList,(jl_value_t*)pre_data,jl_box_float64(0.1));
    
    // Protect `var` until we add its reference to `refs`.
    JL_GC_PUSH1(&retRL);

    const size_t nsize = jl_array_dim(retRL,0);
    int64_t* p = (int64_t*)jl_array_data(retRL);
    
    JL_GC_POP();

```

There is a small error in the documentation, it will not work, if you do not add “(jl\_value\_t\*)” infront of your data pointer, in this case, data\_pre.

Kind regards
