Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created December 25, 2013 06:43
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 taiyoh/8120754 to your computer and use it in GitHub Desktop.
Save taiyoh/8120754 to your computer and use it in GitHub Desktop.
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