I have a function imported from c, the signature is like this:
pub extern fn foo(input: some_ptr, output: [*c][*c]u8) void;
Now let's preallocate a buffer called buffer to store the output.
And I have to mod the buffer ptr like this to fit into the foo function:
const buffer = allocator.alloc(u8, capacity) catch unreachable;
defer allocator.free(buffer);
var buffer_ptr: [1][*c]u8 = .{@ptrCast(buffer)}; // I have to construct a 2D array
c.foo(&input, &buffer_ptr);
Is this the correct way? I can get the correct answer from this code, but I guess there are potential issues in it.
By the way, in rust I managed to pass the buffer like this:
let mut buffer = vec![0u8; 1024];
c.foo(&mut input, &mut buffer.as_mut_ptr());
No two dimensional array is needed in rust.