That struct is not ABI compatible to the given struct, which I believe was the original question. To get an ABI compatible version, you'll have to use the same types as the C version. Since unions aren't supported in an ABI compatible way, this generally does not work for such structs, but in this case you can use a single pointer.
On Sat, Jun 27, 2015 at 4:42 PM, Stefan Karpinski <[email protected]> wrote: > type ITree > n::Int > children::Union(Vector{Int},Vector{ITree}) > end > > julia> t = ITree(123, [1,2,3]) > ITree(123,[1,2,3]) > > julia> ITree(234, [t]) > ITree(234,[ITree(123,[1,2,3])]) > > On Sat, Jun 27, 2015 at 10:50 AM, <[email protected]> wrote: > >> I am new to Julia with mostly C and some MATLAB background. Julia seems >> to provide an easy way to write C like code with MATLAB ease! To get >> started, I am trying understand C interface. Is it be possible to create a >> Julia type for the following struct? >> >> typedef struct itree { >> bool isLeaf; >> int n; //number of elements >> union { >> int *i; //(isLeaf == 1): pointer to int array >> struct itree **s; //(isLeaf == 0): pointer to itree array >> }; >> } itree; >> >> It seems, that the size of the pointer should be the same. So, anonymous >> union should be possible. >> I would appreciate any suggestions. >> >> Thanks, >> ~Sue >> >> >
