4

Possible Duplicate:
An irb-type tool for C/C++

I'm working on some C extensions, and I miss being able to test code interactively.

Community
  • 1
  • 1
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114

2 Answers2

4

The closest you'll get is gdb, which can be used as an almost REPL for C.

Example from the article:

~% gdb ./test
(gdb) break main
Breakpoint 1 at 0x8048452
(gdb) run
Starting program: /home/pcl/sandbox/test
Breakpoint 1, 0x08048452 in main ()
(gdb) set $a = malloc(1234)
(gdb) call sprintf($a, "Hello %d", 12345*12345*12345)
$1 = 15
(gdb) print (char*)$a
$2 = 0x96c6008 "Hello 170287977"
(gdb) print (unsigned int)atoi("-1")
$3 = 4294967295
(gdb) print (unsigned int)atoi("4294967295")
$4 = 2147483647

To get a better idea of everything that's possible and not in gdb, take a look at the manual and this refcard.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
1

See this other question: Is it possible to build a interactive C shell?

Another, more generic, tool I like is hsandbox, though is not really interactive.

Community
  • 1
  • 1
Gustavo Giráldez
  • 2,610
  • 18
  • 12