Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

As far as my understanding goes, compilers are meant for developers compiling their code into executable (machine-code) files. Compilers don't extend to a client's machine or end-user system.

Instead, developers just use the compiler to convert their code into machine code, which is then transported to the other machines for use as applications.

Do compilers have a function outside of this process? If so, when are they used?

share|improve this question
20  
Yes, compilers compile code. –  Tom Squires Aug 30 '11 at 14:34
    
@Tom : I read somewhere that C-compilers are installed on various machines, including gaming consoles. Does this mean we write code in C, then that is shipped to these devices, where are compiled by the compiler and then executed by interpreter ? –  Pankaj Upadhyay Aug 30 '11 at 14:39
3  
@Pankaj Upadhyay: It's possible that code could get sent to a machine and then compiled by an internal process. It's unlikely the user of the device would ever see this happening or know about it. It might be done if parts of code need to be compile for specific hardware and solutions that test for hardware at runtime are too slow, leading to the need to distribute code and compile during install. Maybe... –  FrustratedWithFormsDesigner Aug 30 '11 at 14:53
3  
@Pankaj No game consoles ship with compilers, but some can be installed on them. Sony provided a version of Linux and GCC that could be installed on the PS2 for example. Other people have cracked/hacked their way to getting other OSs and software onto consoles. –  IronMensan Aug 30 '11 at 14:54
3  
@Stargazer: Did you mean: "No, compilers translate from a source language into a target language"? Omitting the comma makes your sentence mean the opposite of your intended meaning. –  Daniel Pryden Aug 30 '11 at 16:59

7 Answers 7

up vote 14 down vote accepted

Yes and no. Yes, the classical scenario is a developer using a compiler to generate machine code from source code, and the machine code is then distributed to the users.

There are a few exceptions to this though. First, many open source projects are distributed primarily (or even exclusively) in source code form, and expect the end user to install them by typing in a couple of commands like make and then make intall. This will invoke the compiler, linker, etc., to generate the machine code from the source code for that users computer. In these cases, however, the process of building and installing is (at least intended to be) automated to the point that the user rarely needs much knowledge of it beyond the fact that if they've never installed a source code-only package previously, their package manager will typically list some "development" package as a prerequisite for installing the application they really care about (though some still see this as unfriendly to end users).

Another exception (that's been alluded to, but not explained very well in the other answers I've seen) is just-in-time (JIT) compilers. A couple of obvious examples of JIT compilers are the Microsoft Common Language Runtime (CLR) and the Java Virtual Machine (JVM). In these cases, there are normally two entirely separate compilers involved in translating source code into machine code. One is used by the developer. However, rather than generating machine code directly, it generates a machine-independent byte code. The CLR/JVM then includes a second compiler, entirely separate from the first, that converts those byte codes to machine code for the target computer.

I should add that the second compiler isn't strictly necessary. Early versions of the JVM (for one example) just interpreted the byte codes instead of compiling them. This often carries a fairly serious performance penalty though, so most reasonably recent JVMs intended for production use include a JIT compiler.

share|improve this answer
    
I guess you have summed up the answer pretty well. But, since the karl answer has double the votes, i will wait until this one gets half the vote. Anyone disagrees let me know –  Pankaj Upadhyay Aug 30 '11 at 17:41
7  
@Pankaj Accept whichever one you feel best answered your question for you, not just that with the most votes. –  Hugo Aug 30 '11 at 18:17
    
@Hugo this isn't the answer with the most votes. –  rightfold Sep 17 '11 at 19:28

Yes, compilers are mainly used by developers, with a couple of notable exceptions. End users sometimes use compilers to compile and install the latest open source software, even if they don't make any changes to the code. Also, some programming languages don't have compilers. They use interpreters instead that "compile" on the fly. In that case, end users need to have the interpreter installed on their machines.

share|improve this answer
4  
If we were to restrict the definition of "compilers" to mean programs that generate executable files, then this would be a good answer. However, that is merely a subset of the true definition of "compiler" –  Stargazer712 Aug 30 '11 at 15:13
1  
Mentioning the "notable exceptions" only made the answer more confusing. Compilers are used by developers, period. If you are compiling some open source software from sources, you are a developer. –  Jan Soltis Aug 30 '11 at 16:40
13  
@Jan Soltis: I disagree. I've compiled the Linux kernel from source: does that mean that I am a Linux kernel developer? I've never modified Linux kernel code or submitted a patch -- I would say that means I'm not a kernel developer. Plus, for the several years that I used Gentoo as my primary operating system, I compiled every single piece of software on the machine. However, the vast majority of those were compiled automagically by the Portage package management system. I would argue that in that case I was acting as an end user but not as a developer. –  Daniel Pryden Aug 30 '11 at 16:55
7  
@Jan Soltis: I am aware that that is your opinion. I respectfully disagree. I provided counterarguments to support my position, while you continue to make unsupported assertions. You seem to think that there is a sharp line between "developer" and "end user" which I do not believe exists. –  Daniel Pryden Aug 30 '11 at 19:13
5  
Downloading sources and then running "make install" is not being a developer. It is definitely an end-user operation. –  Kristopher Johnson Aug 30 '11 at 19:44

That's right -- compilers compile source code into executable form, which is then linked into an executable binary file by a linker. Source code can also be executed directly by an interpreter such as one of the many command-line shells (C-shell, bash, zsh, etc.), awk, sed, and so on.

It can be hard to draw a clear line between "developer" and "end user" unless you limit your discussion to a specific product. Developers are all "end users" of the tools they use, and "end users" may have development tools such as compilers and interpreters installed on their machines.

share|improve this answer
2  
Ok, I'm going to -1 this one, because there is a lot of misunderstanding here about compilers. Compilers translate code from a source language into a target language. Saying they generate machine code is similar to saying that vehicles have 4 wheels (yes, most vehicles have 4 wheels, but a motorcycle is a vehicle too. In the same way, most compilers generate machine code, but a C# -> VB converter is a compiler as well) –  Stargazer712 Aug 30 '11 at 15:28
1  
@Stargazer712, I assure you that there's no misunderstanding -- I know very well what compilers do, thanks. But if someone who doesn't know asks me what a car is, I'd probably say that a car has four wheels despite the fact that some don't. A pedantic definition often confuses more than it explains to a person trying to come to grips with a concept. "Compiler" can also be a job description, but mentioning that wouldn't help here. –  Caleb Aug 30 '11 at 16:05

compilers are meant only for developers for compiling their programming-language code to executable(machin-code) files

I would say "compilers are meant primary for developers ...". But I have seen examples where programs generate new programming-language code on-the-fly and therefore need a compiler to be installed on the end users machine. That does not mean the end-user has to work with the compiler by itself.

Possible reasons for this program design:

  • performance: think of a rule-driven application where the rules are stored in some kind of end-user data store and you have some mass-data to be processed by those rules. Instead of interpreting the rules again and again, a program generates the processing code first, compiles it and runs it against the data to be processed

  • think of a program where the end user can add some kind of math formula and the developer of the program does not want to implement his own parser/interpreter for this. Instead, the program takes this formula, makes some additions to transform it into a valid piece of program code, let the compiler compile it and runs it afterwards.

share|improve this answer
    
hmm.... That does not mean the end-user has to work with the compiler by itself. That pretty much explains and clarifies. –  Pankaj Upadhyay Aug 30 '11 at 14:56

Administrators may also have a need for using programming languages in writing scripts to perform various automated tasks. For example, having a script that deletes old log files off a server after 90 days to free up some disk space. The language used to write the script has to be interpreted or compiled so that it can be run on the system.

share|improve this answer

No

A compiler is defined as a program that translates code from one language into another (see Wikipedia). The most common use of compilers is to translate the source language into machine code, but this does define the word "compiler".

For example, Python generates byte-code when it imports a module, and thus fits within the definition of a compiler (because it converts from the source language, Python, into the target language, Python byte-code).

Another example is the V8 JavaScript engine. It converts JavaScript into x86 machine code, and thus fits into the definition of a compiler as well. Not only does V8 fit the definition of a compiler, but it is included in Chrome and is very widely used on client machines.

share|improve this answer

One case would be for an application that dynamically generated code at runtime, and then ran the generated code. This code would need to be compiled at runtime.

Edit: There are other exceptions, but they had already been mentioned in other answers.

share|improve this answer
    
+1 just say JIT –  gnat Aug 30 '11 at 15:21
1  
The V8 engine in Chrome is not an oddball exception. –  Stargazer712 Aug 30 '11 at 15:22
    
Updated to clarify. I realize there are other exceptions. –  Morgan Herlocker Aug 30 '11 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.