In this chapter, we saw a very powerful tool in the Go arsenal: CGO. This allows a Go application to run C code, which, in turn, can invoke Go functions. We saw that it requires a special import statement, import "C", which is a pseudo package that contains all the C code available to Go. To export Go code and make it available to C, there is a special comment, //export, which makes the Go function available in the C namespace.
We saw that the C and Go type systems are very similar for some things, but very different for others. We saw that strings and byte arrays can be converted to C types, and vice versa. Integers in C and Go are also pretty similar, the main difference being the int type. In C, this is 4 bytes, while in Go, it is 4 or 8 bytes, depending on the architecture. Floats are also pretty similar, with a 4- and 8-bit version in both C and Go...