Skip to content

Instantly share code, notes, and snippets.

@akkijp
Created October 17, 2015 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkijp/8d2844fb9e82bcc680bf to your computer and use it in GitHub Desktop.
Save akkijp/8d2844fb9e82bcc680bf to your computer and use it in GitHub Desktop.
go言語の中でc言語を利用する
package main
/*
#include <stdlib.h>
typedef int (*compare_t)(const void* a, const void* b);
int compareInts(int*, int*);
static void qsortInts(int* data, int len) {
qsort(data, len, sizeof(int), (compare_t)compareInts);
}
*/
import "C"
import . "fmt"
//export compareInts
func compareInts(a, b *C.int) C.int {
return *a - *b
}
func main() {
data := [...]C.int{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9}
C.qsortInts(&data[0], C.int(len(data)))
Println(data)
}
@akkijp
Copy link
Author

akkijp commented Oct 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment