unexpected type: ... with cgo in Go -
i'm new go , trying larn how phone call c go. wrote programme open named semaphore, value , print screen. when run go build semvalue.go error: ./semvalue.go:16:14: unexpected type: ...
what mean? doing wrong?
package main import "fmt" // #cgo ldflags: -pthread // #include <stdlib.h> // #include <fcntl.h> // #include <sys/stat.h> // #include <semaphore.h> import "c" func main() { name := c.cstring("/fram") defer c.free(name) fram_sem := c.sem_open(name, c.o_creat, c.mode_t(0644), c.uint(1)) var val int ret := c.sem_getvalue(fram_sem, val) fmt.println(val) c.sem_close(fram_sem) } thank you.
the message confusing, until realize ... variadic portion of c function. can't utilize c variadic functions straight go, you'll have write little wrapper in c phone call sem_open.
a couple more notes:
c.free should called c.free(unsafe.pointer(name)) val needs *c.int sem_getvalue uses errno, should phone call ret, err := c.sem_getvalue... go
No comments:
Post a Comment