有什么像IRB for C?

时间:2011-06-22 20:18:13

标签: c ruby

  

可能重复:
  An irb-type tool for C/C++

我正在研究一些C扩展,但我错过了能够以交互方式测试代码的方法。

2 个答案:

答案 0 :(得分:3)

您最接近的是gdbwhich can be used as an almost REPL for C

文章中的例子:

~% 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

为了更好地了解可能的所有内容,而不是gdb,take a look at the manualthis refcard

答案 1 :(得分:1)

请参阅另一个问题:Is it possible to build a interactive C shell?

我喜欢的另一个更通用的工具是hsandbox,但不是真的互动。

相关问题