C++ - Generating interfaces

Sunday, February 7, 2021

Wrote a blog entry on my personal blog regarding C++ interface generation using variadic templates.

When you write a programming language translator, it is useful to be able to expose features of the underlying system easily, i.e. to connect to what is often referred to as native functions. In this post, I show how modern C++ makes it possible to entirely automate this process.

Using variadic templates, it is possible – and relatively easy – to let the compiler generate all the boilerplate code connecting your translator to any native C function. Adding a C function to your translator then boils down to a simple macro call that can look like this: NATIVE(fn).