Is C ++ code converted to C during the compilation process?

I read that the original C ++ implementation by Bjarne Stroustrup used a compiler called Cfront , which converted C ++ to C during the compilation process.

Is this still the case with modern compilers (most of them?)?

I could not find a good answer using Google (or I could not find the correct search terms).

edit . This is not an exact duplicate, because I ask for up-to-date / modern ones. But both questions and answers apply.

+7
c ++ c compilation
source share
3 answers

Absolutely not. The CFront method for doing things has become untenable a long time ago. There are some C ++ constructs without interpreting C, especially exceptions, and stamping a C-source literal for each instance of the template is a bit ridiculous. The whole reason Bjarne stopped making Cfront was impossible.

However, a common way to downgrade the code to a more useful IR, such as LLVM IR, and GCC also has an internal IR, before converting to machine code.

+13
source share

The short answer is no. Modern C ++ compilers generate their own code directly.

There is no reason why you cannot compile C ++ to C, there is simply no real reason to do this, so you add an extra step in the compilation process, which just as easily does not exist. However, there are several more options if for some reason you really need C code: the Comeau C ++ compiler emits C code in order to port your C ++ to platforms where the C ++ compiler may not exist (which very few these days), and Clang uses LLVM as a backend code generator that has C as one of many target languages. (edit: of these parameters, the first is deprecated and the second is no longer supported)

In any case, C is not like the code you entered: it is significantly less readable than machine code. The days that a method has accessed function calls with this , of course, are long gone - it is rather a "compilation" rather than a "conversion".

+4
source share

No, modern compilers, such as GCC and clang (and others based on LLVM), usually consist of two parts: back-end and front-end. The front descriptors compile the source code language into some intermediate representative element, for example, LLVM IR.

The back-end generates machine code on the target platform, possibly using some optimizations from this intermediate form.

0
source share

All Articles