Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

C REPL

I've often wondered if you could construct a read-eval-print loop for C (or a language atop C that wanted to use C libraries). I think the hard part would be handling error conditions. One way of looking at it (as Dan put it) is that the C language spec allows you to crash whenever something unexpected occurs, while most languages have defined semantics for all inputs. (This isn't a slam on C -- leaving lots of things unspecified allows for a faster implementation. For example, array indexing can be done without bounds checking because indexing off the bounds of an array is one of those undefined conditions.)

It just occurred to me, though, that you could fork() before running each line of code. Then if that code caused a crash, you'd still have the old process state around, while if it didn't crash you could kill the old process. The only problem is for code that involved I/O, you wouldn't get a second chance... hmm. I suppose the same is true for a "normal" REPL anyway.

[Edit: I later got around to implementing this. See the C REPL tag.]
Tags: c repl, programming languages
Subscribe

  • your vcs sucks

    I've been hacking on some Haskell stuff lately that's all managed in darcs and it's reminded me of an observation I made over two years ago now (see…

  • ghc llvm

    I read this thesis on an LLVM backend for GHC, primarily because I was curious to learn more about GHC internals. The thesis serves well as an…

  • found my bug!

    Not too interesting, but this has been bugging me for a week. Been working on a toy program that proxies a TCP connection. It was working fine for…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 14 comments

  • your vcs sucks

    I've been hacking on some Haskell stuff lately that's all managed in darcs and it's reminded me of an observation I made over two years ago now (see…

  • ghc llvm

    I read this thesis on an LLVM backend for GHC, primarily because I was curious to learn more about GHC internals. The thesis serves well as an…

  • found my bug!

    Not too interesting, but this has been bugging me for a week. Been working on a toy program that proxies a TCP connection. It was working fine for…