I often find myself needing to do arrays of things to interface with C.
What’s the Ada way of doing this?
It seems like passing an array with An_Array'Address seems to work, but I’m not sure how the array’s bounds are stored and affect the layout of that array. This is particular importance since I’m looking at trying to store multiple arrays of potentially difference sizes allocated in memory sequentially.
struct Vec3 {
float x, y, z;
};
uint32_t size = 10;
Vec3 points = new Vec3[size];
passArrayToFunc(&points[0], size);
type Vec3 is record
X, Y, Z : Interfaces.C.c_float;
end record with Convention => C;
type Vec3_Array is array (Positive range <>) of aliased Vec3;
procedure Pass_Array_To_Func
(Pointer : not null access Vec3;
Size : Interfaces.C.int) with Import, Convention => C;
Points : Vec3_Array (1 .. 10);
begin
Pass_Array_To_Func (Points (Points'First)'Access, Points'Length);
An idea is to pass address of the first element of the array and length of the array.