# BitArray unboxing

**URL:** <https://discourse.julialang.org/t/bitarray-unboxing/4558>\
**Category:** General Usage\
**Tags:** question, embedding\
**Created:** [June 30, 2017, 5:41am UTC](https://discourse.julialang.org/t/bitarray-unboxing/4558 "2017-06-30T05:41:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 30, 2017, 5:41am UTC](https://discourse.julialang.org/t/bitarray-unboxing/4558/1 "2017-06-30T05:41:01Z")

</div>

Is casting to this struct enough?

```julia
typedef struct {
   jl_array_t *chunks;
   int64_t len;
   jl_value_t *dims;
} jl_bit_array_t;

```

Like, I tried this

```julia
typedef struct {
    jl_array_t *chunks;
    int64_t len;
    jl_value_t *dims;
} jl_bit_array_t;

jl_bit_array_t *ret = (jl_bit_array_t*) jl_eval_string(".!([true false; true true; false false])");

int64_t len = ret->len;
uint64_t *zData = (uint64_t*) jl_array_data(ret->chunks);
jl_value_t *dimensions = ret->dims;
printf("dims: %s type \n",jl_typeof_str(ret->dims));

```

`len` and `chunks` are correctly aligned and the data is correct, but `dims`, whatever I do with it, it results in segfault.  
In the above code also, `jl_typeof_str` resulted in segfault.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 30, 2017, 6:14am UTC](https://discourse.julialang.org/t/bitarray-unboxing/4558/2 "2017-06-30T06:14:50Z")

</div>

> [@tastelessjolt](#):
>
> Is casting to this struct enough?

No, it’s a bits tuple, so it corresponds to a C array, not pointer.

Also note that the fields are not part of the API of BitArray, it can be changed at any time.

---

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 30, 2017, 7:14am UTC](https://discourse.julialang.org/t/bitarray-unboxing/4558/3 "2017-06-30T07:14:56Z")

</div>

If it’s a C array, how to find the length of the C array?

> [@yuyichao](#):
>
> Also note that the fields are not part of the API of BitArray, it can be changed at any time.

I didn’t get what `fields` are here.

Edit:  
I was able to get the Tuple, the array ends with a 0. Using that I found out the length of the array. Is there a better and cleaner way?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 30, 2017, 10:11am UTC](https://discourse.julialang.org/t/bitarray-unboxing/4558/4 "2017-06-30T10:11:06Z")

</div>

> [@tastelessjolt](#):
>
> how to find the length of the C array?

You need to know it. You can know it from the julia type.

> [@tastelessjolt](#):
>
> I didn’t get what fields are here.

The struct you try to declare.

> [@tastelessjolt](#):
>
> the array ends with a 0

No it doesn’t always.
