IGCC - a real-eval-print loop for C/C++
August 31, 2009 [C, C++, IGCC, STL, Tech]When you first hear about the Read-Eval-Print Loop you might well think "So what?" as I did.
What's so great about being able to type commands interactively?
But the thing is that it creeps up on you.
Everyone already knows programming is an interactive thing - we need constant feedback to validate our ideas. Programming on paper is incredibly frustrating because you have to plough on with assumptions that are probably wrong.
It's just so comfortable to be able to try out ideas in an interactive interpreter.
I mean, it's really not much hassle to create a new directory, make a new file, edit the file to contain the code you want to try, remember the right command to compile it, then run the program and see the results, is it?
Well, no, it isn't, but it's enough of a hassle that sometimes you don't bother and you try it out in the code you are really working on, and if your work is like mine that means a minimum of 5 minutes to compile and link, and there you are playing foosball again when you could be getting something done.
The REPL gives you a place to try throwaway things extremely quickly, and when you're working with something beautiful like Python it's easy to get addicted.
So my mind started to wander and it struck me that a pale imitation of the REPL could be made for us poor C++ programmers, and it would generally serve the purposes I've described above.
So IGCC was born. Its name means "Interactive GCC" and it's a read-eval-print loop for C++ (and, for most cases it will work for C too).
It uses the real GCC underneath, so you know you are running the exact code you would be (and it's somewhat easier to write than a custom C/C++ interpreter) and all it does is take away the hassle of creating a simple program and compiling it with GCC.
It wraps your code in a standard C program, includes some common dependencies, and compiles it, printing the results of running them immediately. Using it looks like this:
$ ./igcc g++> int a = 5; g++> a += 2; g++> cout << a << endl; 7 g++> --a; g++> cout << a << endl; 6 g++>
Apart from all the sugar that I'd love to add, the main missing features are some kind of equivalent of the Python dir command, and code completion.
It's not rocket science, but it might make you a little bit more interactive in your C and C++ coding, which might save you valuable foosball time.
Enjoy, improve, etc. IGCC.
Foosball image taken from http://en.wikipedia.org/wiki/File:Baby_foot_artlibre_jnl.jpg