That works. The problem I had earlier with a panic was caused by my C
library which was returning null as an error condition. Once the C code
was fixed it worked as you said.
Thanks.
On Thu, Apr 30, 2020 at 2:18 PM Jan Mercl <0xj...@gmail.com> wrote:
> On Thu, Apr 30, 2020 at 10:06 PM Dean
>
> That compiles but it still panics:
>
> test: bad machine line11=(null), return
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4949f2]
>
> goroutine 1 [running]:
> main.(*LineStruct).MachineName(...)
>
C.GoString((*C.char)(_name))
On Thu, Apr 30, 2020 at 1:21 PM Dean Schulze
wrote:
> This expression
>
> C.GoString(C.char*(_name))
>
> gives this error:
>
> type _Ctype_char is not an expression
>
> On Thu, Apr 30, 2020 at 2:09 PM Bruno Albuquerque wrote:
>
>> Not pretty but if you
This expression
C.GoString(C.char*(_name))
gives this error:
type _Ctype_char is not an expression
On Thu, Apr 30, 2020 at 2:09 PM Bruno Albuquerque wrote:
> Not pretty but if you are sure the array is zero-terminated, you can
> simply cast it to the correct type:
>
>
On Thu, Apr 30, 2020 at 10:06 PM Dean Schulze wrote:
>
> That gives this error (which I've gotten with just about everything I try):
>
> cannot use _name (type *[25]_Ctype_char) as type *_Ctype_char in
> argument to _Cfunc_GoString
Oh yeah, should have been probably `C.GoString([0])`.
Forgot Go
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*)())
(untested)
On Thu, Apr 30, 2020 at 1:06 PM Dean Schulze
wrote:
> That gives this error (which I've gotten with just about everything I try):
>
> cannot use _name
That gives this error (which I've gotten with just about everything I try):
cannot use _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
On Thu, Apr 30, 2020 at 8:17 PM 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 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