注意事项:
传入C函数中的slice需要以&array[0]
的形式进行,而不能单纯使用&array
,因为go中的slice数据结构不仅仅具有首地址。
类型对应表
type | C | go |
---|---|---|
char | C.char | byte |
signed | C.schar | int8 |
unsigned char | C.uchar | uint8 |
short int | C.short | int16 |
short unsigned int | C.ushort | uint16 |
int | C.int | int |
unsigned int | C.uint | uint32 |
long int | C.long | int32/int64 |
long unsigned int | C.ulong | uint32/uint64 |
long long int | C.longlong | int64 |
long long unsigned int | C.ulonglong | uint64 |
float | C.float | float32 |
double | C.double | float64 |
wchar_t | C.wchar_t | |
void * | unsafe.Pointer |
例子
1 | package main |