Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the C++ code compile to assembly codes?

Tags:

Does C++ code compile to assembly code? If we have C++ code, will we be able to get assembly code?

like image 846
Ata Avatar asked Jan 24 '11 06:01

Ata


People also ask

What does C code compile into?

Compiling a C Program. Compiling is the transformation from Source Code (human readable) into machine code (computer executable).

Does all code compile to assembly?

That being said, no, not all programs are turned into assembly language. If we exclude just-in-time compilation, interpreted languages liked ruby, lisp, and python, as well as programs that run on a virtual machine (VM) like java and c# are not turned into assembly.


1 Answers

The vast majority of C++ compilers will convert the C++ source into object files (machine code with enough control information to be linked into an executable). They may actually generate assembly language as an interim step and even use a separate assembler for processing the assembler source, but you'll generally never see that. For example, you have to actually go out of your way to get gcc to generate assembly code (.s file) by using the -S flag. Normally, you would never see the assembly.

But the C++ standard doesn't mandate the final form that's output from the compiler, just that the code has to behave in a certain way when you run it.

In fact, the earliest C++ "compilers" actually generated C source code and then compiled that.

You can have your C++ compiler generate object code, Java byte code, or even GWBASIC, should you be feeling masochistic.

like image 191
paxdiablo Avatar answered Oct 01 '22 11:10

paxdiablo