56

I am on osx. I found this http://neugierig.org/software/c-repl/ but the links on that page for code seem to be broken.

Surya
  • 4,922
  • 8
  • 41
  • 54
  • 3
    Just adding a link to this post with some c-repl examples: http://stackoverflow.com/questions/1459678/where-can-i-find-c-repl-documentation/6902522#6902522 – sdaau Nov 13 '13 at 02:29
  • See also [Is there an interpreter for C?](https://stackoverflow.com/questions/584714/is-there-an-interpreter-for-c) – ggorlen Sep 02 '21 at 19:38
  • ClangRepl looks good: https://clang.llvm.org/docs/ClangRepl.html – Brian Aug 17 '23 at 23:07

3 Answers3

34

Just found the IGCC (Interactive GCC) REPL. I like it.

Example:

./igcc

g++> int a = 1, b = 2;
g++> printf("%d\n", a + b);
3
g++> 

And it gives you compile errors like this:

g++> c = 3;
[Compile error - type .e to see it.]
g++> .e
<stdin>:14:1: error: use of undeclared identifier 'c'
c = 3;
^

(SF download: http://sourceforge.net/projects/igcc/files/)

userABC123
  • 1,460
  • 2
  • 18
  • 31
29

gdb makes a pretty good REPL. You can't define new functions there, but you can evaluate expressions (including those with side effects).

gcbenison
  • 11,723
  • 4
  • 44
  • 82
  • 15
    An example of how to use gdb as a reply would be nice. –  Apr 03 '13 at 23:26
  • 2
    An example of how to use gdb: 1) `gdb /bin/ls` 2) `print "Hello world"[0]` Of course it gets more involved than that... but even that simple example illustrates a common C idiom in a repl – gcbenison Apr 04 '13 at 00:46
  • 1
    On Mac OS with gdb 6.3.50, the example above give: "evaluation of this expression requires the target program to be active" – Snowcrash Aug 19 '13 at 12:48
  • 3
    @snow aha - right you are, gdb won't actually work as a repl unless it is attached to some actually running process. There is more than one way to achieve this. Usually breaking on "main" works on Linux, but system programs like "ls" often don't have this. The following worked on Centos5: 1) gdb /bin/ls 2) break readdir 3) run 4) print "hello world" – gcbenison Aug 19 '13 at 17:21
  • 5
    gdb seems a bit finicky sometimes... for instance: `(gdb) print printf("test\n");` `No symbol "printf" in current context.` which is funny, because I just stepped over a call to printf! – Michael Apr 14 '15 at 19:24
  • 2
    This answer fails to meet what I would consider minimum qualifications for an answer: `(gdb) int a = 5; Ambiguous command "int a = 5;": internals, interpreter-exec, interrupt. (gdb) ` – Evan Carroll Aug 23 '18 at 20:23
28

Seems like the code of c-repl can now be found at a Github repository. It seems to be a dead project, though (last commit was 3 years ago), so I'd suggest looking into alternatives as well:

Niklas B.
  • 92,950
  • 18
  • 194
  • 224