Matthew Bedford Matthew Bedford - 1 year ago 151
C Question

Julia - fixed size array in C struct

I need to make a Julia type corresponding to a C struct that has a fixed size array:

struct cstruct {
int arr[N] //N known at compile time

I have defined Julia types corresponding to other C structs with arrays like this:

type jstruct

But as I understand it, this only works when
is a pointer, not an array of a specific size. How can I ensure that the offsets of elements coming after
remain the same in both languages?

Answer Source

When you define a C struct with a fixed size array (or with the array hack), the data are stored directly inline within that struct. It's not a pointer to another region. The equivalent Julia structure is:

type JStruct{N}

That will store the integers directly inline within the struct.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download