ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] > [cgo教程](https://chai2010.cn/advanced-go-programming-book/ch2-cgo/readme.html) ## 注意事项 1. go还可以嵌入C代码,但是不可以嵌入C++代码 1. 可以通过某些方式调用C++ API(如SWIG) 1. import “C” 和包含C代码之间是没有空行的 ## 数值类型 | C语言类型 | CGO类型 | Go语言类型 | | --- | --- | --- | | char | C.char | byte | | singed char | C.schar | int8 | | unsigned char | C.uchar | uint8 | | short | C.short | int16 | | unsigned short | C.ushort | uint16 | | int | C.int | int32 | | unsigned int | C.uint | uint32 | | long | C.long | int32 | | unsigned long | C.ulong | uint32 | | long long int | C.longlong | int64 | | unsigned long long int | C.ulonglong | uint64 | | float | C.float | float32 | | double | C.double | float64 | | size\_t | C.size\_t | uint | 除了`GoInt`和`GoUint`之外,我们并不推荐直接访问`GoInt32`、`GoInt64`等类型。更好的做法是通过C语言的C99标准引入的`<stdint.h>`头文件 | C语言类型 | CGO类型 | Go语言类型 | | --- | --- | --- | | int8\_t | C.int8\_t | int8 | | uint8\_t | C.uint8\_t | uint8 | | int16\_t | C.int16\_t | int16 | | uint16\_t | C.uint16\_t | uint16 | | int32\_t | C.int32\_t | int32 | | uint32\_t | C.uint32\_t | uint32 | | int64\_t | C.int64\_t | int64 | | uint64\_t | C.uint64\_t | uint64 |