-3

I don't know much about the compilation steps. As I understand it, when I click on the compile buton of my IDE, the is a phase of preprocessing, compiling (creating assembly code), creating binary code (object files) and then linking. But why isn't the compiler directly going from the preprocessing to a binary file? (since basicaly this is just a translation into 1s and 0s without choosing how things are going to be handled by the processor->which was done in the compilation step).

roi_saumon
  • 489
  • 4
  • 13

1 Answers1

1

This question has been asked and answered many times now...

The basic tools are an assembler and a linker, a compiler has some assembly required, which sure someone could write in machine code, but you likely have an assembler at your disposal. And you will need a linker. Without using assembly language on paper or otherwise take even a simple program and write it in machine code directly. Then write that same program using assembly language and assemble it. Which is more error prone as a programmer? Would you rather try to write and debug and maintain a compiler that outputs machine code or assembly language? You very very likely would have a working assembler and a linker at your disposal.

Thus the name toolchain, compile, assemble, link...with gcc for example it is actually a handful of programs just to compile then you get to assemble and link.

The exceptions would be the folks that really really want to skip the step like tcc. The folks that climb the mountain just because it is there, rather than go around. Or are maybe doing a just in time like llvm but I bet they dont actually skip the step even just in time. And who uses llvm for JIT compared to the number of folks that use it as a compiler? llc does now have a direct to object option, but it is experimental and not sure how exactly they are doing it, have not researched that.

old_timer
  • 69,149
  • 8
  • 89
  • 168