Dean,
Command cgo
https://golang.org/cmd/cgo/#hdr-Go_references_to_C
In C, a function argument written as a fixed size array actually requires a
pointer to the first element of the array. C compilers are aware of this
calling convention and adjust the call accordingly, but Go cannot. In Go,
you must pass the pointer to the first element explicitly: C.f(&C.x[0]).
Peter
On Thursday, April 30, 2020 at 2:17:37 PM UTC-4, Dean Schulze 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)
>
> I get an error like
>
> cannot use p.hostname (type [25]_Ctype_char) as type *_Ctype_char in
> argument to _Cfunc_GoString
>
> I've seen some examples but they all rely on *C.char and I haven't found
> any way to get a [25]_Ctype_char to a pointer representation.
>
> What do I need to do to convert a char[] to []byte of string 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/e61da6dc-aeaf-4f13-8ba2-937e6f058943%40googlegroups.com.