17

Is there a way i can run c++ code as interpreted instead of compiled? so i can edit code and write functions on the fly?


Related:

Community
  • 1
  • 1
  • 1
    While possible, this is not really a good idea. C++ is really poorly suited for interpreters. Its basic strength - speed - is gone, its shortcomings ( relatively low-level, no error-checking against wrong pointers etc) are still there. Not everything can be done in the interpreter. There are many so much better suited interpreted languages, and there are jit compilers for C++ - "compile and run", making it behave very much like interpreter from user's point of view while being in fact compiled. – SF. Mar 11 '10 at 09:03

6 Answers6

10

Take a look at Ch, an embeddable C++ interpreter.

Ch is an embeddable C/C++ interpreter for cross-platform scripting, shell programming, 2D/3D plotting, numerical computing, and embedded scripting. Ch is a free and user-friendly alternative to C/C++ compilers for beginners to learn C/C++.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
5

Ch and CINT (usually as part of the ROOT system) will interpret C++. However, my experience with CINT has not been good: the language support is not complete (particularly where templates are concerned), the execution is much slower, there has been a history of bugs with e.g. variable scope and loop exiting, and (IMO) it's more hassle than it's worth. As a language, C++ is singularly ill-designed for interpreted use.

If you need to run interpreted code, why not use a modern interpreted language like Python or Ruby? A tool like SWIG can be used to connect them to existing C/C++ libraries if needed.

andybuckley
  • 1,114
  • 2
  • 11
  • 24
3

Try these:

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
2

CINT certainly has single-stepping. I'm not sure about modification on the fly, though.

Alex Rintt
  • 1,618
  • 1
  • 11
  • 18
Mark
  • 6,269
  • 2
  • 35
  • 34
0

This doesnt exactly answer your question, but perhaps it will help.

The MS C++ compiler supports Edit and Continue, which allows you to stop, make changes, recompile & continue without shutting down you program.

John Dibling
  • 99,718
  • 31
  • 186
  • 324
0

I saw a presentation on ccons at CUSEC's demo camp back in January. Its aim is to provide an interactive interpreter like python's. It was in its early stages then but impressed me none the less.

C-o-r-E
  • 583
  • 7
  • 16