Interactive Programming… in C

I’ve been kind of interested in a type of “livecoding” where changes to a code base are immediately reflected in a running program. I’ve seen Inigo Quilez (author of the famed do this with a scaffold that he wrote using OpenGL. Literally as he types new shader code, the changed shader is loaded and executed, and the new graphic image forms the background of his editor.

You can see an example of this here:

I started working on a similar framework, and got the basics working (except that I didn’t write my own editor, but merely ran vi in a window and updated the fragment shaders running in a separate window) but today I discovered this kind of cool idea: doing the same sort of thing in C.

Chris Wellons wrote on his blog back in 2014 about a set of techniques that could be used to do the same sort of interactive stuff in C.  The basic idea is to write a framework which constantly monitors a shared library, and when it is updated, reloads the library.  If it is not, then it calls an “update” loop.  I don’t think this is helpful for all sorts of programs, and there are a few details to be sorted, but it’s kind of cool.  I can imagine giving this a try on one or two projects that I’ve been pondering.  Archived for future reference.


Addendum: David Parrot posted this to my twitter feed:
There was a problem connecting to Twitter.

In case twitter integration fails, it’s a link to Casey Muratori’s Homemade Hero on instantaneous live coding. I haven’t had a lot of time to watch the videos yet, but they seem very cool.

One thought on “Interactive Programming… in C”

  1. I’ve found this technique useful for rapid development of audio generation software on Linux.

    One thing that caught me out was differences in the way that different compilers save object files. I recall that one compiler (either Clang or gcc) appeared to save the compiled file in two stages (saving a header first, then appending executable data at a later stage, perhaps), which confused the monitoring part of the code when it tried to load an incomplete library.

Comments are closed.