I’m sorry for the bold font here below but I couldn’t understand how to get rid of it.
I want zig to import a C file and let zig compile it for me. The C file also include a .h file that defines a struct. I have simplified my real files here but the problem is the same.
----------------------------------simple.h------------------------
struct simple
{
unsigned long* ptr_to_val;
};
unsigned long add_value( struct simple *s_ptr );
----------------------------------simple.c------------------------------------------
#include "simple.h"
unsigned long add_value( struct simple *s_ptr )
{
return *(s_ptr->ptr_to_val) + 1;
}
I want to call add_value() from zig with a legal value of s_ptr->ptr_to_val .
I declare my struct variable in the test part in main.zig like this.
-------------------------------------------------main.zig-----------------------------
const test_file = @cImport(
{
@cInclude("simple.c");
});
test "simple test" {
var ret: c_ulong = undefined;
var st = test_file.simple{.dummy = 2, .ptr_to_val = undefined};
// How to give the st.ptr_to_val a value that I can use when calling add_test() ?
ret = test_file.add_value(st.ptr_to_val)
}