I am trying to pass a C struct to Julia using ccall
Here is my file in C:
#include <stdio.h> typedef struct { float a; float b; } TestStruct; TestStruct getStruct() { TestStruct s = {3.0f, 5.0f}; printf("Created struct a: %fb: %f\n", sa, sb); return s; }
Then I compile this into a shared library for use with Julia.
Here is my Julia file:
immutable TestStruct a::Cfloat b::Cfloat end struct = ccall((:getStruct, "libteststruct"), TestStruct, ()) println("Got struct a: ", struct.a, " b: ", struct.b)
When I ran this file, I would expect to get
Created struct a: 3.000000 b: 5.000000 Got struct a: 3.0 b: 5.0
However, instead I get
Created struct a: 3.000000 b: 5.000000 Got struct a: 3.0 b: 0.0
a always correct, but b always 0 .
This works when I use doubles in a struct instead of a float, but I need to use a float.
Thanks.
source share