Posts

Showing posts from January, 2021

Designing a C interface for complex types

Update Nov 2022: After doing 4-5 interfaces in this fashion, if I had it to do over, I would probably use SWIG .  I passed on it initially because it had only one maintainer on GitHub.  However, given the time I ended up sinking into writing & debugging custom interfaces, it may have been worth the risk. Let’s say we are designing an interface to pass a complex type between C++ modules. If there is any possibility of the two modules being built by different compilers, different versions of the same compiler, or for different platforms, the C++ ABI could be different, making updates potentially very brittle.  The unfortunate result is we’ll need to use C functions & structures for the interface.  The same is true of C++ to another language. As an example, let’s say our module houses a lookup we want to share: If we wanted to make this lookup available to another module, due to reasons previously stated, we can’t pass our nice C++ types. So, we would ne...