>
> So what should I pass instead? Or should I switch to Julia 0.4? How stable
> is 0.4?


- you could write the function as `p_add(double x, double y, double z)` or
- pass a pointer to the Julia instance and copy the fields on the C side.

0.4-dev is not really recommended unless you are somewhat adventurous or
you know you need a specific feature.

(for general use, note also that depending on what APIs you are calling,
you could just do the full array-population on the Julia side and pass a
pointer to the array because Julia's arrays have C-compatible memory layout)

On Sun, Jun 21, 2015 at 11:51 AM, Daniel Carrera <[email protected]> wrote:

>
> On 21 June 2015 at 17:41, Isaiah Norton <[email protected]> wrote:
>
>> I would expect gibbrrish at first because the memory is uninitialized.
>> What version of Julia? Passing structs by value doesn't work on 0.3.
>>
>
> I have 0.3.8 -- How should I pass a struct then? Btw, I can confirm that
> passing struct by value doesn't work. If I write:
>
> void particles_add(struct particle pt){
>     while (Nmax <= N){
>         Nmax += 128;
>         particles = realloc(particles,sizeof(struct particle)*Nmax);
>     }
>     particles[N] = pt;
>     printf("pt.x, pt.y, pt.z = %f, %f, %f\n", pt.x, pt.y, pt.z);
>     N++;
> }
>
>
> in Julia I get:
>
> julia> add(x=1,y=2,z=3)
> pt.x, pt.y, pt.z = 0.000000, 0.000000, 0.000000
>
>
> So what should I pass instead? Or should I switch to Julia 0.4? How stable
> is 0.4?
>
>
>
>> Also note that you will need to reload the particles ptr any time you
>> read from it because realloc can invalidate the pointer.
>>
> Good to keep in mind. Thanks.
>
> Cheers,
> Daniel.
>

Reply via email to