I'm trying to make go wrapper for C library. But can't even compile simple code.
Image that we have string variable:
s := "some go string"
And we have C-function that looks next (C-code I mean):
void foo(char const *);
And I can't understand (or guess) how to write Go-code.
C.foo(s) won't work and cause me next error message:
> cannot use s (type string) as type *_Ctype_char in function argument
What is the right way to pass string arguments?
Thanks for help.
--
Best regards, Viacheslav Chumushuk
email/jabber: vo...@root.ua
Ukraine, Khmelnitsky
You can find some examples of the back and forth in
https://github.com/str1ngs/go-git
-justin
On Fri, May 20, 2011 at 07:34:09AM -0700, Justin Lilly <jus...@justinlilly.com> wrote:
> To convert from go string to C string, you're looking for
> C.CString(my_go_string) to convert back, you're looking for
> C.GoString(my_c_string)
>
> You can find some examples of the back and forth in
> https://github.com/str1ngs/go-git
>
> -justin
--
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.MyFunc(cName)
Jeremy
http://jeremy.cowgar.com
On Fri, May 20, 2011 at 11:06:47AM -0400, Jeremy Cowgar <jco...@gmail.com> wrote:
> Don't forget to free if it necessary, just my method of doing things,
> prefix the created C var with c.
>
> cName := C.CString(name)
> defer C.free(unsafe.Pointer(cName))
>
> C.MyFunc(cName)
>
> Jeremy
> http://jeremy.cowgar.com
--