cgo - How to construct C struct in Go side? -
i need call c function needs pointer of struct argument. here's 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, think have malloc memory construct position object , pass pointer c function. maybe need free memory. seems c.cstring() did. how can that? there code example? thx.
how call c golang clear generated stub. use go build -work src/main.go
generate stub , working directory. find function prototype in _obj/_cgo_gotypes.go
file. i.e. can following generated go stub:
type _ctype_position _ctype_struct__position type _ctype_struct__position struct { //line :1 index _ctype_int //line :1 offset _ctype_int //line :1 } func _cfunc_read(p0 *_ctype_char, p1 *_ctype_struct__position, p2 **_ctype_char) (r1 _ctype_int)
if have c header file this:
typedef struct _position { int index; int offset; }position; extern int read(const char* filename, const position* pos, const char** data);
btw need reference c function in go source make dependency go build
generate referenced function stub.
Comments
Post a Comment