7

In the C++ tag wiki, it is stated that

C++ is a ... (usually) compiled ... programming language ...

Yet Wikipedia and cplusplus.com assert that C++ is a compiled language without mentioning any exceptions.

Could you please tell us the reason why C++ is usually, yet not always, a compiled language? When can C++ be deemed a non-compiled language?


Wikipedia:

C++ is a compiled language, with implementations of it available on many platforms.

cplusplus.com:

... is a compiled language. C++ compiles directly to a machine's native code, allowing

This may suggest that there are non-compiled forms of C++. What makes the wiki to state 'usually'?

Herpes Free Engineer
  • 2,425
  • 2
  • 27
  • 34
  • 2
    I think there has been some *interpreter* of some *subset* of C++. Look into [Ch](http://www.softintegration.com/) and [Cling](https://root.cern.ch/cling) – Basile Starynkevitch Feb 14 '18 at 16:49
  • 4
    eg the ROOT framework has a [c++ interpreter](https://root.cern.ch/cint) – 463035818_is_not_an_ai Feb 14 '18 at 16:49
  • 1
    I'm guessing the prevalence of LLVM and clang. Though that's a compiler too. – Alex Feb 14 '18 at 16:50
  • 1
    Read: https://stackoverflow.com/q/69539/6525260. Here is [one interpreter called Cling](https://github.com/vgvassilev/cling). – Arnav Borborah Feb 14 '18 at 16:50
  • 4
    Note: cplusplus.com is generally a poor reference site full of errors. Prefer cppreference.com – Jesper Juhl Feb 14 '18 at 16:55
  • 2
    At last,**the difference between a compiler and an interpreter is very blurry.** [SBCL](http://sbcl.org/) looks and smells like an interpreter, but it actually compiles to machine code *every* [REPL](https://en.wikipedia.org/wiki/REPL) interaction. – Basile Starynkevitch Feb 14 '18 at 16:57

4 Answers4

10

Because "C++" as defined by the C++ Standard is only a programming language, operating in an abstract machine. Implementations are free to do whatever they want to emulate the behaviour of that abstract machine.

Therefore, regardless of whether someone actually makes a C++ interpreter, saying that C++ is always compiled would be an unfounded assumption.

Quentin
  • 62,093
  • 7
  • 131
  • 191
7

There is no technical reason why you can't write a C++ interpreter rather than a compiler and I believe some have been written in the past.

C is also a (usually) compiled language, but I myself wrote a (slow, recursive decent) C89 interpreter some 20 years ago. C++ is just a (much) harder version of the same problem.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
2

There are some interpreters for subsets of C++ (related question), but the overwhelming majority of C++ work is done using compilers. Using interpreters is so rare that no C++ literature or sizeable C++ library or program not explicitly about/for those interpreters will restrict itself to the subset of C++ that can be used on an interpreter.

With C++, it's actually more common to compile further C++ on the fly than interpret any.

For whatever it's worth, the most recent related news I've read (on Hacker News) was about a C++17 REPL.

user433534
  • 1,043
  • 6
  • 8
1

In most cases C++ is compiled but, e.g., cling is a C++ interpreter. I haven't tried it much but it seems to be a fairly complete C++ implementation.

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380