github.com/goplus/llgo@v0.8.3/cl/_testrt/qsort/in.go (about)

     1  package main
     2  
     3  import (
     4  	"unsafe"
     5  
     6  	"github.com/goplus/llgo/internal/runtime/c"
     7  )
     8  
     9  //go:linkname qsort C.qsort
    10  func qsort(base c.Pointer, count, elem uintptr, compar func(a, b c.Pointer) c.Int)
    11  
    12  func main() {
    13  	a := [...]int{100, 8, 23, 2, 7}
    14  	qsort(c.Pointer(&a[0]), 5, unsafe.Sizeof(0), func(a, b c.Pointer) c.Int {
    15  		return c.Int(*(*int)(a) - *(*int)(b))
    16  	})
    17  	for _, v := range a {
    18  		c.Printf(c.Str("%d\n"), v)
    19  	}
    20  }