1. 13
    1. 2

      The gist of it is Go exports functions to other languages by generating a header file with extern "C" wrapper functions which are named as indicated by the programmer with magic //export <symbol> comments.

      Now I’m wondering what sort of code these wrappers execute internally in order to interface with the Go runtime. Virtualized languages typically have a complete API that lets programmers create instances of the virtual machine, bind functions and variables, and then load code into it. I’m not sure Go employs that model.

      The simple ABI afforded by C seems to be the default solution to all interoperability problems. Will we ever see a foreign language interface that does not go through C? Why can’t Go talk to C++ directly?

      1. 1

        Cockroach db wrote a great article about cgo and the cost of using it: https://www.cockroachlabs.com/blog/the-cost-and-complexity-of-cgo/

        The post i wrote shows how go talks to c++ directly, but c is the lingua franca of programming, most ffis are designed to work with the model of c abis, there is a great article about that: https://faultlore.com/blah/c-isnt-a-language/#