Questions tagged [compilation]

Compilation is the transformation of source text into some other form or representation. The most common usage of this tag is for questions concerning transformation of a programming language into machine code. This tag is normally used with another tag indicating the type of the source text such as a programming language tag (C, C++, Go, etc.) and a tag indicating the tool or compiler being used for the transformation (gcc, Visual Studio, etc.).

Compilation is the transformation of source text into some other form or representation. The software tool used is called a compiler. Most compilers process the source text to generate some sort of machine code for a target hardware machine. Some compilers generate the "machine code" for a target virtual machine (e.g. bytecode for a Java Virtual Machine).

In all of these cases the compiler creates new files of the transformed source text and these new files are used in some other processing step up to and including executing directly on hardware or virtual hardware.

Interpretation is the processing of source text by a software tool called an interpreter. Interpreters immediately execute the sense of the source text without generating a new, externally visible form of the source text. Compilers generate a new, externally visible form of the source text which is then executed by some other device whether actual hardware or virtual machine.

The lines between interpreters and compilers have blurred somewhat with the introduction of languages whose tools generate an intermediate language which is then executed on an internal virtual machine. The traditional compiler generates machine code files which are then further processed into an application to execute. The traditional interpreter parses the source text line by line performing some action indicated by the line of source text at the time the line of source is read.

A C or C++ compiler generates object files containing binary code which are then processed by a linker into an application and executed. A Java compiler generates class files containing Java Virtual Machine byte code which are then combined into a Java application and executed.

Engines for scripting languages such as Php and JavaScript may use an internal compiler to generate an intermediate form of the source text which is then executed by an internal virtual machine. For some types of applications the intermediate form is temporarily stored or cached so that if the same script is being used by multiple threads or multiple repetions in a short time span, the overhead of rescaning the source text is reduced to improve efficiency. However these are not considered to be compilers.

Compilation usually involves the following steps:

  • Scanning - The scanner is responsible of tokenizing the source code into the smallest chunks of information (keywords, operators, brackets, variables, literals etc.).
  • Parsing - The parser is responsible with creating the Abstract Syntax Tree (AST) which is a tree representation of the code according to the source language definition.
  • Optimization - The AST representing the code is sent through various optimizers in order to optimize for speed or space (this part is optional).
  • Code generation - The code generator creates a linear translated document from the AST and the output language definition.

In many languages and compilers there are additional steps added to the process (like pre-processing), but these are language and compiler specific.

In most cases, where compilation is a part of the build/make/publish process, the output of the compiler will be sent to the linker which will produce the ready-to-use files.

Questions using this tag should be about the compilation process, not about how to write compilers for example (use the compiler tag for that).

15850 questions
1584
votes
5 answers

Why does changing 0.1f to 0 slow down performance by 10x?

Why does this bit of code, const float x[16] = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6}; const float z[16] = {1.123, 1.234, 1.345, 156.467, 1.578,…
GlassFish
  • 14,051
  • 3
  • 15
  • 22
582
votes
18 answers

What does a just-in-time (JIT) compiler do?

What does a JIT compiler specifically do as opposed to a non-JIT compiler? Can someone give a succinct and easy to understand description?
Michiel Borkent
  • 31,814
  • 15
  • 78
  • 134
571
votes
15 answers

Why does C++ compilation take so long?

Compiling a C++ file takes a very long time when compared to C# and Java. It takes significantly longer to compile a C++ file than it would to run a normal size Python script. I'm currently using VC++ but it's the same with any compiler. Why is…
Dan Goldstein
  • 22,493
  • 10
  • 44
  • 51
475
votes
5 answers

What are .a and .so files?

I'm currently trying to port a C application to AIX and am getting confused. What are .a and .so files and how are they used when building/running an application?
Dunc
  • 6,777
  • 9
  • 27
  • 35
399
votes
9 answers

How can I check the syntax of Python script without executing it?

I used to use perl -c programfile to check the syntax of a Perl program and then exit without executing it. Is there an equivalent way to do this for a Python script?
Eugene Yarmash
  • 119,667
  • 33
  • 277
  • 336
371
votes
16 answers

Error:java: invalid source release: 8 in Intellij. What does it mean?

Im trying to compile some code in I'm using Intellij Ultimate 13.1.4, but I get the following error and I have no idea what it means: Information:Using javac 1.7.0_55 to compile java sources Information:java: Errors occurred while compiling module…
David says Reinstate Monica
  • 16,634
  • 19
  • 69
  • 108
343
votes
4 answers

Less aggressive compilation with CSS3 calc

The Less compilers that I'm using (OrangeBits and dotless 1.3.0.5) are aggressively translating body { width: calc(100% - 250px - 1.5em); } into body { width: calc(-151.5%); } Which is obviously not desired. I'm wondering if there is a way to…
Nick Babcock
  • 5,842
  • 3
  • 24
  • 39
286
votes
13 answers

Why do you have to link the math library in C?

If I include or in a C program I don't have to link these when compiling but I do have to link to , using -lm with gcc, for example: gcc test.c -o test -lm What is the reason for this? Why do I have to explicitly link…
Nope
  • 29,782
  • 41
  • 91
  • 115
275
votes
26 answers

Displaying the build date

I currently have an app displaying the build number in its title window. That's well and good except it means nothing to most of the users, who want to know if they have the latest build - they tend to refer to it as "last Thursday's" rather than…
Mark Mayo
  • 10,833
  • 11
  • 49
  • 82
264
votes
10 answers

Why compile Python code?

Why would you compile a Python script? You can run them directly from the .py file and it works fine, so is there a performance advantage or something? I also notice that some files in my application get compiled into .pyc while others do not, why…
ryeguy
  • 60,742
  • 51
  • 186
  • 256
228
votes
3 answers

Java method with return type compiles without return statement

Question 1: Why does the following code compile without having a return statement? public int a() { while(true); } Notice: If I add return after the while then I get an Unreachable Code Error. Question 2: On the other hand, why does the…
Willi Mentzel
  • 21,499
  • 16
  • 88
  • 101
220
votes
3 answers

What is the purpose of the "Prefer 32-bit" setting in Visual Studio and how does it actually work?

It is unclear to me how the compiler will automatically know to compile for 64-bit when it needs to. How does it know when it can confidently target 32-bit? I am mainly curious about how the compiler knows which architecture to target when…
Aaron
  • 9,226
  • 13
  • 35
  • 53
215
votes
22 answers

Why is Swift compile time so slow?

I'm using Xcode 6 Beta 6. This is something that's been bugging me for some time now, but it's reaching a point where it's barely usable now. My project is starting to have a decent size of 65 Swift files and a few bridged Objective-C files (which…
apouche
  • 8,943
  • 5
  • 37
  • 45
211
votes
6 answers

How to fix error with xml2-config not found when installing PHP from sources?

When I try to install php 5.3 stable from source on Ubuntu (downloading compressed installation file from http://www.php.net/downloads.php) and I run ./configure I get this error: configure: error: xml2-config not found. Please check your libxml2…
TroodoN-Mike
  • 14,537
  • 12
  • 50
  • 77
210
votes
15 answers

How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

I want to dynamically create a template. This should be used to build a ComponentType at runtime and place (even replace) it somewhere inside of the hosting Component. Until RC4 I was using ComponentResolver, but with RC5 I get the following…
Radim Köhler
  • 117,533
  • 47
  • 231
  • 321
1
2 3
99 100