C.GoString((*C.char)(&p.mach_name)) On Thu, Apr 30, 2020 at 1:21 PM Dean Schulze <dean.w.schu...@gmail.com> wrote:
> This expression > > C.GoString(C.char*(&p.mach_name)) > > gives this error: > > type _Ctype_char is not an expression > > On Thu, Apr 30, 2020 at 2:09 PM Bruno Albuquerque <b...@gmail.com> wrote: > >> Not pretty but if you are sure the array is zero-terminated, you can >> simply cast it to the correct type: >> >> C.GoString((C.char*)(&p.hostname)) >> >> (untested) >> >> >> On Thu, Apr 30, 2020 at 1:06 PM Dean Schulze <dean.w.schu...@gmail.com> >> wrote: >> >>> That gives this error (which I've gotten with just about everything I >>> try): >>> >>> cannot use &p.mach_name (type *[25]_Ctype_char) as type *_Ctype_char in >>> argument to _Cfunc_GoString >>> >>> It seems to be the fixed length of the char[] that gives cgo a problem. >>> >>> >>> On Thursday, April 30, 2020 at 1:46:34 PM UTC-6, Jan Mercl wrote: >>>> >>>> On Thu, Apr 30, 2020 at 8:17 PM Dean Schulze <dean.w...@gmail.com> >>>> wrote: >>>> > >>>> > I must be missing something pretty simple, but I have a C struct like >>>> this: >>>> > >>>> > typedef struct line >>>> > { >>>> > char hostname[HOSTNAME_MAX]; >>>> > char ip[IP_MAX]; >>>> > ... >>>> > } >>>> > >>>> > When I try to do the simple thing >>>> > >>>> > C.GoString(p.hostname) >>>> >>>> An array of a fixed size within a C struct is a value (the same as in >>>> Go), but C.GoString expects a pointer to a C.char. Try >>>> `C.GoString(&p.hostname)`. >>>> >>>> Not tested. Note that if hostname is not properly zero terminated, >>>> your code will crash or misbehave. >>>> >>>> (Automatic array decay applies to C code, but not in Go.) >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to golang-nuts+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/72d6cdaa-a6ca-4a60-b60a-a3a42de5d8d6%40googlegroups.com >>> <https://groups.google.com/d/msgid/golang-nuts/72d6cdaa-a6ca-4a60-b60a-a3a42de5d8d6%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEd86TxG01zjZuoNmdtaR8-Zh%2BF9b4ZEjeiWm%3DAOGE1nk5OZyw%40mail.gmail.com.