Re: [go-nuts] CGO - convert a c.char array to string

2018-08-07 Thread Ian Lance Taylor
On Mon, Aug 6, 2018 at 11:34 PM, nicolas_boiteux via golang-nuts wrote: > > yes i used the code from this page: > > func Float64bits(f float64) uint64 { > return *(*uint64)(unsafe.Pointer(&f)) > } > > adapted to my use case > > *(*int)(unsafe.Pointer(limit) As the docs say, that is only permissib

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-06 Thread nicolas_boiteux via golang-nuts
yes i used the code from this page: func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) } adapted to my use case *(*int)(unsafe.Pointer(limit) Le lundi 6 août 2018 19:53:07 UTC+2, Ian Lance Taylor a écrit : > > On Sun, Aug 5, 2018 at 10:29 PM, nicolas_boiteux via

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-06 Thread Ian Lance Taylor
On Sun, Aug 5, 2018 at 10:29 PM, nicolas_boiteux via golang-nuts wrote: > > thanks you, the A3 community finaly help me to solve the last problem > > for index := C.int(0); index < argc; index++ { > out = append(out, C.GoString(*argv)) > argv = (**C.char)(unsafe.Pointer(uintptr

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread nicolas_boiteux via golang-nuts
thanks you, the A3 community finaly help me to solve the last problem *for index := C.int(0); index < argc; index++ {out = append(out, C.GoString(*argv))argv = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(argv)) + offset))}* I dont really understand why but it see

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread nicolas_boiteux via golang-nuts
i found another thing. func RVExtensionArgs(output *C.char, outputsize C.size_t, input *C.char, argv **C.char, argc C.int) { var offset = unsafe.Sizeof(uintptr(0)) var out []string *limit := *(*int)(unsafe.Pointer(&argc))if limit < 1000 { for index := 0; index < limi

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread nicolas_boiteux via golang-nuts
Miki & Jan thanks i tested the both methods. Dll compiles normaly, but program crash. With Miki code the first time, i run the code, i saw that string array contains also other characters that not come from argv. Le dimanche 5 août 2018 15:02:47 UTC+2, Jan Mercl a écrit : > > On Sun, Aug 5, 201

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread Jan Mercl
On Sun, Aug 5, 2018 at 2:50 PM nicolas_boiteux via golang-nuts < golang-nuts@googlegroups.com> wrote: > not sure to understand cause the iteration in your example is done on os interface from golang not from c char array :( Not sure what you mean by 'os interface'. Here's the part that iterates *

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread nicolas_boiteux via golang-nuts
not sure to understand cause the iteration in your example is done on os interface from golang not from c char array :( Le dimanche 5 août 2018 12:48:20 UTC+2, Jan Mercl a écrit : > > On Sun, Aug 5, 2018 at 12:29 PM nicolas_boiteux via golang-nuts < > golan...@googlegroups.com > wrote: > > > it r

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread Jan Mercl
On Sun, Aug 5, 2018 at 12:29 PM nicolas_boiteux via golang-nuts < golang-nuts@googlegroups.com> wrote: > it returns : > > .\armago_x64.go:19: cannot convert p (type **_Ctype_char) to type uintptr Ok, this time bit more tested jnml@4670:~/tmp> cat main.c #include int main(int argc, char **argv)

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread nicolas_boiteux via golang-nuts
it returns : .\armago_x64.go:19: cannot convert p (type **_Ctype_char) to type uintptr I am a little lost with this conversion, I do not understand how the iterator should work. I hope there was a simple command like GoString to do it. Le dimanche 5 août 2018 12:16:13 UTC+2, Jan Mercl a écrit

Re: [go-nuts] CGO - convert a c.char array to string

2018-08-05 Thread Jan Mercl
On Sun, Aug 5, 2018 at 12:05 PM nicolas_boiteux via golang-nuts < golang-nuts@googlegroups.com> wrote: > Do you know a standard method to iterate & convert all the argv array in one golang string array ? Something like (not tested): var a []string for p := argv; *p != nil; p = (**C.char)(unsafe.