Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What I say below is only approximate, but captures what I believe are some essential things you need to know.</p> <p>In C++ the phases of compilation are (1) preprocessing, (2) actual compilation, and (3) linking. </p> <p>The preprocessing phase takes as input a <em>cpp</em> file and does textual substitutions guided by directives like "#include" and "#define". In particular, the content of <em>h</em> files is copied verbatim in the place of "#include" directives. </p> <p>The actual compilation produces machine code that lives in <em>o</em> files. Most instructions that appear in <em>o</em> files are instructions that the processor knows about, with the exception of <em>call function_name</em>. The processor doesn't know about names, it only knows about addresses.</p> <p>In the (static) linking phase, multiple <em>o</em> files are put together. Now we know where the definition of a function ends up. That is, we know its address. The <em>call function_name</em> instructions are transformed into <em>call function_address</em> instructions that the processor knows how to execute. The <em>lib</em> files are precompiled bundles of <em>o</em> files, and they are taken as input by the (static) linker. They contain the machine code for functions such as <em>printf</em>, <em>memset</em>, etc.</p> <p>Some names are not transformed into addresses during static linking. These are the names that refer to functions whose definitions live in a <em>dll</em> file. (Like <em>lib</em> files, <em>dll</em> files are also bundles of <em>o</em> files.) These leftover names are converted into proper addresses while the program runs (that is, at runtime) in a process called dynamic linking. This process involves finding the proper <em>dll</em> file and locating the function with the given name.</p> <p>In Java the story is a little different. First, there is no preprocessing. Second, the result of the compilation is not machine code but bytecode, and lives in <em>class</em> files (not <em>o</em> files). Bytecode is similar to machine code but at a higher level of abstraction. In particular, in bytecode you can say <em>call function_name</em>. This means that there is no static linking phase and that the lookup of the function by name is always done at runtime. The bytecode runs not on the real machine but on a virtual machine. C# is similar to Java, the main difference being that the bytecode (called Common Intermediate Language in the case of C#) is slightly different.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload