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,001
  • 2
  • 24
  • 29

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
  • 60,592
  • 7
  • 125
  • 183
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
  • 28,933
  • 3
  • 44
  • 66
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
  • 993
  • 5
  • 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
  • 145,940
  • 13
  • 211
  • 371