I am trying to call a Go function from C code, but I encountered a issue which I can't really explain:
C:
char * ret;
CheckDpkgInfo(&ret);
printf("%s", ret);
Go:
func CheckDpkgInfo(dpkg_c **C.char) {
*dpkg_c = C.CString("whatever")
}
This works, but not when I simply return a c string from Go (segfault):
C:
char * ret = CheckDpkgInfo();
printf("%s", ret);
Go:
func CheckDpkgInfo() *C.char {
return C.CString("whatever")
}
If I understood the documentation correctly CString should call malloc, therefore I really don't get why the printf segfaults. Thanks!