user813853
user813853

Reputation:

When we compile C++ what do we get ? binary code ? assembleur code?

In Java, when we compile a file, we get byte code which is then executed with the virtual machine.

How about in C++ ? What happens when we compile a file with g++, what do we get assembler code or binary code?

Upvotes: 1

Views: 2245

Answers (1)

doron
doron

Reputation: 28872

C and C++ are compiled into an object file. These files contain the machine code that can directly be executed on the target processor. However before being fully executable, we will need to link all the object files together. This does not change the code other than to fill in all the addresses for missing symbols. The format of the code remains the same.

On linux, the object files are in ELF format.

One can however compile a file with link time optimizations. This will generally also produce a bytecode in addition to the machine code. When one links with link time optimization, the linker will then convert the byte code into machine code while performing cross compilation unit (object file) optimization.

Upvotes: 3

Related Questions