代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"unsafe"
)
/*
#include <stdio.h>
#include <stdlib.h>
unsigned char cBytes[16]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
static unsigned char *AllocateBytes() {
printf("--------allocate--------\n");
for(int i = 0; i < 16; i++){
printf("cBytes[%d]=%c\t", i, cBytes[i]);
}
printf("\n--------%p--------\n", &cBytes);
return cBytes;
}
*/
import "C"
func main() {
// 1. 定义声明GO byte[] 切片
goBytes := make([]byte, 16)
for i := 0; i < cap(goBytes); i++{
goBytes[i] = byte(i)
}
// 2. 输出该字节数组
for _, value := range goBytes {
fmt.Printf("%b ", value)
}
fmt.Println()
cBytes := C.AllocateBytes()
_ = cBytes
fmt.Printf("address = %v\n", cBytes)
unsafeBytes := (*[16]byte)(unsafe.Pointer(cBytes))[:]
for i := 0; i < 16; i++{
fmt.Printf("%b ", unsafeBytes[i])
}
fmt.Println()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。