[CCALL/INTEROP] Get a `Ptr` for the last (or arbitrary) element of an array

Sorry, I tried to find it myself in documentation but was not able to find a good answer.

I want to wrap a C function that takes two pointers, one for the first element of an array, the other for the last element of the same array. I want to create such array in Julia (probably with Vector, the elements are an isbits struct I already created following the recommended translation rules) so Julia owns the memory, and then just pass the two pointers needed to the function (which will change the elements in the range). I have found no way to obtain a pointer to the last element of the Vector (or an arbitrary position) so I can pass it as the second argument of the C funcion.

Okay, it seems like the docs of CCall assume the reader knew about pointer(array[, index]) or Ref(array[, index]) my question now is which one should I use?

Seems like Ref(a, firstindex(a)) and Ref(a, lastindex(a)) will do the job.

1 Like