Proper use of empty structure with CGO

Work with gssapi.h

struct gss_name_struct;
typedef struct gss_name_struct * gss_name_t;

I am trying to figure out how to properly initialize a variable containing this,

var output_name C.gss_name_t = &C.struct_gss_name_struct{}

But functions like gss_import_name act as if I passed them a null pointer. What is the correct way to properly initialize and use these empty structures using CGO?

+4
source share
1 answer

typedefs . Go - C, , . go C-, . go .

C , , Go. cgo, , . go tool cgo -godefs filename.go cgo . , go .

// statement in the original .go file
//var output_name C.gss_name_t = &C.struct_gss_name_struct{}

// output from cgo -godefs
// var output_name *[0]byte = &[0]byte{}

// or more succinctly
output_name := &[0]byte{}

// output_name can be converted directly to a C.gss_name_t
fmt.Printf("%+v\n", output_name)
fmt.Printf("%+v\n", C.gss_name_t(output_name))
+5

Source: https://habr.com/ru/post/1536581/


All Articles