Created
October 17, 2015 22:57
-
-
Save akkijp/8d2844fb9e82bcc680bf to your computer and use it in GitHub Desktop.
go言語の中でc言語を利用する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
出典元:http://www.oki-osk.jp/esc/golang/cgo-osx.html