I need to call a C function which needs a pointer of struct as argument. Here's the C code:
struct Position
{
uint64_t index;
uint64_t offset;
};
int read(const char* filename, const Position* pos, const char** data)
So in Go code, I think I have to malloc memory to construct a Position object and pass its pointer to C function. Maybe I also need to free memory. It seems like what C.CString() did. So how can I do that? Is there any code example? THX.
How call c from golang is clear by the generated stub. use
go build -work src/main.go
to generate the stub and get the working directory. find the function prototype in_obj/_cgo_gotypes.go
file. i.e. I can get the following generated go stub:if i have the c header file like this:
BTW you need reference the c function in go source to make a dependency for
go build
to generate the referenced function stub.