Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created Dec 25, 2013
Embed
What would you like to do?
package main
/*
#include <stdio.h>
void test(unsigned char* b) {
printf("fetch: %s\n", b);
b[0] = 'b';
b[1] = 'a';
b[2] = 'r';
}
*/
import "C"
import (
"fmt"
"reflect"
"unsafe"
)
func main() {
buf := []byte("foo")
fmt.Printf("original: %s\n", buf)
data := (*reflect.SliceHeader)(unsafe.Pointer(&buf)).Data
C.test((*C.uchar)(unsafe.Pointer(data)))
fmt.Printf("result: %s\n", buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment