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
  • 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