C/C++ REPLs

When working in C++, I occasionally find myself pining for a REPL like those for Python/Haskell/Scheme/[your language here]. Given the size and complexity of the language, I find it useful at times to explore certain nooks and crannies, and REPLs can be a quick way to try things out. It turns out that such a beast exists, and its name is CINT.

Putting aside the sheer coolness factor, I haven’t actually used CINT much, and part of this is because (I believe) C++’s design is not amenable to interactive use. CINT does add a few language extensions which make it slightly more usable, including limited “type inference” and looser distinguishing of . from ->. However, the C++ test cases I’ve been coming up with are almost always at least several lines of code consisting of some function/class/template declarations—clumsier to input using readline.

There also exists a REPL for C: Evan Martin’s C-REPL. Unlike CINT, it’s a simpler program that uses incremental compilation tricks. Basically, every time you enter a line, C-REPL generates a source file, which then gets compiled into a shared library, which in turn is dynamically linked with and executed. As such, C-REPL supports the full language, system libraries, anything. And it’s fast. But it only works with C.