Thanks. That is what I was hoping. bool is just a typedefed alias for int.
I will start by looking at ccall() examples in various libraries. Any
suggestions for a good place to start?
On Saturday, June 27, 2015 at 5:14:20 PM UTC-5, Stefan Karpinski wrote:
>
> If you want a C-ABI compatible struct, you can do this:
>
> type ITree
> isLeaf::Cint # there is no "bool" in C, so what is this?
> n::Cint
> ptr::Ptr{Void}
> end
>
>
> Then you can just convert(Ptr{Int}, t.ptr) or convert(Ptr{ITree}, t.ptr)
> depending on t.isLeaf.
>
> On Sat, Jun 27, 2015 at 5:17 PM, Stefan Karpinski <[email protected]
> <javascript:>> wrote:
>
>> I interpreted the question as "how do I do this kind of thing in Julia"
>> rather than how do I make a binary-compatible structure (clearly I'm
>> failing at that).
>>
>> On Sat, Jun 27, 2015 at 4:46 PM, Keno Fischer <
>> [email protected] <javascript:>> wrote:
>>
>>> 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]
>>> <javascript:>> 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] <javascript:>>
>>>> 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
>>>>>
>>>>>
>>>>
>>>
>>
>