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 <javascript:>> 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 <stdio.h>
>
> int main(int argc, char **argv) {
> char **p;
> for (p = argv; *p != 0; p++) {
> printf("%s\n", *p);
> }
> }
> jnml@4670:~/tmp> ccgo main.c && ./a.out abc def ghi
> ./a.out
> abc
> def
> ghi
> jnml@4670:~/tmp> ccgo -o main.go main.c
> jnml@4670:~/tmp> cat main.go
> // Code generated by 'ccgo -o main.go main.c', DO NOT EDIT.
>
> // +build linux,amd64
>
> package main
>
> import (
> "math"
> "os"
> "unsafe"
>
> "github.com/cznic/crt"
> )
>
> const (
> null = uintptr(0)
> )
>
> var (
> _ = math.Pi
> _ = os.DevNull
> _ = unsafe.Pointer(null)
>
> nz32 float32
> nz64 float64
> )
>
> func init() { nz32 = -nz32 }
> func init() { nz64 = -nz64 }
>
> func alloca(p *[]uintptr, n int) uintptr   { r := crt.MustMalloc(n); *p = 
> append(*p, r); return r }
> func preinc(p *uintptr, n uintptr) uintptr { *p += n; return *p }
>
> func main() {
> psz := unsafe.Sizeof(uintptr(0))
> argv := crt.MustCalloc((len(os.Args) + 1) * int(psz))
> p := argv
> for _, v := range os.Args {
> *(*uintptr)(unsafe.Pointer(p)) = crt.CString(v)
> p += psz
> }
> a := os.Environ()
> env := crt.MustCalloc((len(a) + 1) * int(psz))
> p = env
> for _, v := range a {
> *(*uintptr)(unsafe.Pointer(p)) = crt.CString(v)
> p += psz
> }
> *(*uintptr)(unsafe.Pointer(Xenviron)) = env
> X_start(crt.NewTLS(), int32(len(os.Args)), argv)
> }
>
> // linking main.o
>
> // X__ccgo_va_end *void, escapes: true, builtin.h:36:6
> var X__ccgo_va_end = bss + 0
>
> // X__ccgo_va_start *void, escapes: true, builtin.h:37:6
> var X__ccgo_va_start = bss + 8
>
> // Xmain is defined at main.c:3:5
> func Xmain(tls crt.TLS, _argc int32, _argv uintptr /* **int8 */) (r int32) 
> {
> var _p uintptr // **int8
>
> _p = _argv
> _1:
> if (*(*uintptr)(unsafe.Pointer(_p))) == 0 {
> goto _3
> }
>
> crt.Xprintf(tls, ts+0 /* "%s\n" */, *(*uintptr)(unsafe.Pointer(_p)))
> _p += 8
> goto _1
>
> _3:
> return r
> }
>
> // linking crt0.o
>
> // X__stdfiles [3]uintptr, escapes: true, crt0.c:3:15
> var X__stdfiles = bss + 16
>
> // Xenviron **int8, escapes: true, crt0.c:4:6
> var Xenviron = bss + 40
>
> // Xstdin *void, escapes: true, crt0.c:5:6
> var Xstdin = bss + 48 // pointer to void
>
> func init() { *(*uintptr)(unsafe.Pointer(Xstdin)) = X__stdfiles }
>
> // Xstdout *void, escapes: true, crt0.c:5:31
> var Xstdout = bss + 56 // pointer to void
>
> func init() { *(*uintptr)(unsafe.Pointer(Xstdout)) = X__stdfiles + 8 }
>
> // Xstderr *void, escapes: true, crt0.c:5:57
> var Xstderr = bss + 64 // pointer to void
>
> func init() { *(*uintptr)(unsafe.Pointer(Xstderr)) = X__stdfiles + 16 }
>
> // X_start is defined at crt0.c:7:6
> func X_start(tls crt.TLS, _argc int32, _argv uintptr /* **int8 */) {
> crt.X__register_stdfiles(tls, *(*uintptr)(unsafe.Pointer(Xstdin)), 
> *(*uintptr)(unsafe.Pointer(Xstdout)), *(*uintptr)(unsafe.Pointer(Xstderr)), 
> Xenviron)
> crt.X__builtin_exit(tls, Xmain(tls, _argc, _argv))
> }
>
> func init() { *(*uintptr)(unsafe.Pointer(Xstdin)) = X__stdfiles }
>
> func init() { *(*uintptr)(unsafe.Pointer(Xstdout)) = X__stdfiles + 8 }
>
> func init() { *(*uintptr)(unsafe.Pointer(Xstderr)) = X__stdfiles + 16 }
>
> var (
> bss     = crt.BSS(&bssInit[0])
> bssInit [72]byte
> ts      = crt.TS("%s\n\x00")
> )
> jnml@4670:~/tmp> 
>
> I hope you can extract the code for your case from the above mechanically 
> produced Go code. Note that ccgo uses untrptrs instead of normal pointers 
> but that should be an easy adjustment, I hope.
>
> -- 
>
> -j
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to