cgo question

98 views
Skip to first unread message

Elemer Pixard

unread,
Sep 25, 2021, 9:59:45 AM9/25/21
to golang-nuts
I am trying to call the following C function (simplified version from a C library) from Go,
and I got compiler errors:
typedef void device_t;
void open(device_t **dev) {
}

Go Function:
func Open() {
   var dev C.device_t
   C.open(&&dev)
}

Compiler (v1.17) error:
cannot use _cgo0 (type **_Ctype_void) as type *unsafe.Pointer in argument to _Cfunc_open

How to fix that?
Regards.

Elemer Pixard

unread,
Sep 25, 2021, 11:13:04 AM9/25/21
to golang-nuts
Correction: The Go function is:
func Open() {
  var dev *C.device_t
  C.open(&dev)

Elemer Pixard

unread,
Sep 25, 2021, 12:14:37 PM9/25/21
to golang-nuts
Using unsafe.Pointer instead of the C type: C.device_t solved the problem:

func Open() {
   var dev unsafe.Pointer
   C.open(&dev)
Reply all
Reply to author
Forward
0 new messages