Tuesday, February 12, 2019

REPL for C!?

Was instructing a colleague on how to use REPL first, when working on languages like Python/Lua, to try the code snippet interactively. And this thought passed through - "why not a simple REPL for C"? And, that's how I got to hack together a quick shell (bash) script which does just that - a REPL for C!
Of course, C is not interpreted or dynamic, and you cannot do many things that you could do in the REPL of a dynamic language. But, this does save some keystrokes when you want to quickly run and check some code snippet.

The script:
https://gist.github.com/aniruddha-a/2877defd751b20a8f4dbbe04b7b6fe43

The readline helper, with history and completion for often used std functions/types:
https://gist.github.com/aniruddha-a/dfca2c5f88fdc1df5591943422fe0349