So assume you don’t have any problem creating the type (unless you have a too big type you can just create a big enough buffer to pass in the tuple element types). With that you shouldn’t have any problem allocating the object either so I assume you only have problem with accessing elements.
C does not allow unknown type during compile time so you cannot declare the corresponding C type unless you know it at C code compile time in general. In this particular case though, the three methods I mentioned in the first post still all apply.
- You can use the getfield function. It’s accessible in C as
jl_get_field
. It should be pretty obvious to use. This does not need to rely on any C functions in your code, all offset calculation is down in julia runtime, it’s also the slowest. - You can do offset computation yourself. You can easily predict the layout of the object with
n
fields. You can just do the offset computation and loads yourself. ForNTuple
it’s simple enough that you can just cast the pointer tossize_t*
and index it. - It turns out that this is a very special case where it is actually possible to declare a compatible C struct. This require C99 and you can do it as
typedef struct { ssize_t a[]; } ntupleint;