Computer Science
C Compiler
A C compiler is a computer program that translates source code written in the C programming language into machine code that can be executed by a computer. The compiler takes the source code as input and produces an executable file as output. C compilers are essential tools for software development and are widely used in the industry.
Written by Perlego with AI-assistance
Related key terms
1 of 5
9 Key excerpts on "C Compiler"
- eBook - PDF
- Joyce Farrell(Author)
- 2017(Publication Date)
- Cengage Learning EMEA(Publisher)
Your system has been configured to automatically save your work at regular intervals on a nonvolatile storage device—often your hard drive. After a computer program is typed using programming language statements and stored in memory, it must be translated to machine language that represents the millions of on/ off circuits within the computer. Your programming language statements are called source code, and the translated machine language statements are object code. Each programming language uses a piece of software, called a compiler or an interpreter, to translate your source code into machine language. Machine language also is called binary language, and is represented as a series of 0s and 1s. The compiler or interpreter that translates your code tells you if any programming language component has been used incorrectly. Syntax errors are relatively easy to locate and correct because your compiler or interpreter highlights them. If you write a computer program using a language such as C++, but spell one of its words incorrectly or reverse the proper order of two words, the software lets you know that it found a mistake by displaying an error message as soon as you try to translate the program. After a program’s source code is translated successfully to machine language, the computer can carry out the program instructions. When instructions are carried out, a program runs, or executes. In a typical program, some input will be accepted, some processing will occur, and results will be output. C H A P T E R 1 An Overview of Computers and Programming 4 Although there are differences in how compilers and interpreters work, their basic function is the same—to translate your programming statements into code the computer can use. When you use a compiler, an entire program is translated before it can execute; when you use an interpreter, each instruction is translated just prior to execution. - eBook - PDF
C++ Programming
Program Design Including Data Structures
- D. Malik(Author)
- 2017(Publication Date)
- Cengage Learning EMEA(Publisher)
Compiler : A program that translates instructions written in a high-level language into the equivalent machine language. Processing a C 11 Program In the previous sections, we discussed machine language and high-level languages and showed a C 11 statement. Because a computer can understand only machine language, you are ready to review the steps required to process a program written in C 11 . Consider the following C 11 program: #include using namespace std; int main() { cout << My first C++ program. << endl; return 0; } At this point, you need not be too concerned with the details of this program. How-ever, if you run (execute) this program, it will display the following line on the screen: My first C++ program. Recall that a computer can understand only machine language. Therefore, in order to run this program successfully, the code must first be translated into machine language. In this section, we review the steps required to execute programs written in C 11 . The following steps, as shown in Figure 1-2, are necessary to process a C 11 program. 1. You use a text editor to create a C 11 program following the rules, or syntax , of the high-level language. This program is called the source code , or source program . The program must be saved in a text file that has the extension . cpp . For example, if you saved the preceding program in the file named FirstCPPProgram , then its complete name is FirstCPPProgram.cpp . Source program : A program written in a high-level language. 2. The C 11 program given in the preceding section contains the state-ment #include . In a C 11 program, statements that begin with the symbol # are called preprocessor directives. These statements are processed by a program called preprocessor . - eBook - ePub
Scientific Programming: C-language, Algorithms And Models In Science
C-Language, Algorithms and Models in Science
- Luciano Maria Barone, Enzo Marinari, Giovanni Organtini, Federico Ricci Tersenghi(Authors)
- 2013(Publication Date)
- WSPC(Publisher)
object, containing only machine code.Who compiles the compiler?The compiler itself is a program. Thus, before it can be executed, it must also be compiled. To this purpose, we again need a compiler, which in turn must be compiled. How can we resolve this apparent chicken-and-egg problem? The answer is actually relatively easy. Namely, the first compilers were written in machine language. Once we have a simple compiler written in machine language and able to translate a more advanced language, we can write and subsequently compile a more complicated translation program. Continuing this process, we create more and more advanced compilers and finally have the possibility to compile the compiler B with a program A which are both written in the same language.The first self-hosting compiler, i.e., a compiler able to compile its own source code, was written in Lisp in 1962 at the MIT by Timothy Hart and Michael Levin.Today, almost all compilers are written in C, which does thisjob well: the C Compiler is almost always written in the C language. Making a compiler is a typical bootstrap process, i.e., a process in which an initially simple system activates itself by passing through several degrees of complexity. In other words, the system activates itself even if it is not yet fully up and running. Another example of a bootstrap process is the sequence of operations which need to be executed by a computer when it is turned on in order to activate itself: for the computer to work, a program needs to be loaded into its memory, but a program must be loaded into the memory to load other programs!The term bootstrap was borrowed from the like-named strap sewed at the rear top of cowboy boots, helping to get them on easily. It is commonly believed that the bootstrap - Joyce Farrell(Author)
- 2012(Publication Date)
- Cengage Learning EMEA(Publisher)
The translated machine language statements are known as object code . 3 Understanding Computer Components and Operations Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. Although there are differences in how compilers and interpreters work, their basic function is the same — to translate your programming statements into code the computer can use. When you use a compiler, an entire program is translated before it executes; when you use an interpreter, each instruction is translated just prior to execution. Usually, you do not choose which type of translation to use — it depends on the programming language. However, there are some languages for which both compilers and interpreters are available. Watch the video Understanding Computer Hardware and Software . Understanding Simple Program Logic A program whose source code contains syntax errors cannot be fully translated nor can it execute. A program with no syntax errors can execute, but it still might contain logical errors and produce incorrect results. For a program to work properly, you must develop correct logic ; that is, you must write program instructions in a specific sequence, you must not leave any instructions out, and you must not add extraneous instructions. Suppose that you instruct someone to make a cake as follows: Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups of flour The dangerous cake-baking instructions are shown with a Don ’ t Do It icon.- eBook - PDF
Microchip AVR® Microcontroller Primer
Programming and Interfacing, Third Edition
- Steven F. Barrett, Daniel J. Pack(Authors)
- 2022(Publication Date)
- Springer(Publisher)
The job of the compiler is to transform the pro- gram provided by a programmer (filename.c and filename.h) into machine code (filename.hex or filename.elf ) suitable for loading into the microcontroller. Once the source files (filename.c and filename.h) are provided to the compiler, the com- piler executes two steps to render the machine code. The first step is the compilation process. Here the program source files are transformed into assembly code (filename.asm). If the pro- gram source files contain syntax errors, the compiler reports these to the user. Syntax errors are reported for incorrect use of the C programming language. An assembly language program is not generated until the syntax errors have been corrected. The assembly language source file (filename.asm) is then passed to the assembler, which transforms the assembly language source file (filename.asm) to machine code (filename.hex or folename.elf ) suitable for loading to the Microchip processor. In the next section, we discuss the components of a C program. 2.3 ANATOMY OF A PROGRAM Programs written for a microcontroller have a fairly repeatable format. Slight variations exist but many follow the format shown below. //Comments containing program information // - file name: // - author: // - revision history: // - compiler setting information: // - hardware connection description to microcontroller pins // - program description //include files #include //function prototypes A list of functions and their format used within the program //program constants #define TRUE 1 #define FALSE 0 #define ON 1 #define OFF 0 //interrupt handler definitions - No longer available |Learn more
- Gary Bronson(Author)
- 2012(Publication Date)
- Cengage Learning EMEA(Publisher)
As shown, the source program is entered by using an editor program, which is a word-processing program that’s part of the development environ-ment the compiler supplies. Remember, however, that you can begin entering code only after you have analyzed an application and planned the program’s design carefully. An assembly-language program Translation program (assembler) A machine-language program Figure 1.10 Assembly-language programs must be translated Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 31 Chapter 1 A Closer Look: Software, Hardware, and Computer Storage Translating the C++ source program into a machine-language program begins with the compiler. The output the compiler produces is called an object program , which is a machine-language version of the source code. Source code almost always makes use of existing prepro-grammed code—code you have written previously or code the compiler provides, such as mathematical code for finding a square root. Additionally, a large C++ program might be stored in two or more separate program files. Any additional code must be combined with the object program before the program can be executed. It’s the task of the linker to perform this step. The result of the linking process is a machine-language (executable) program that contains all the code your program requires and is ready for execution. The last step in the process is to load the machine-language program into the computer’s main memory for actual execution. - eBook - PDF
- Howard Austerlitz(Author)
- 2014(Publication Date)
- Academic Press(Publisher)
It executes com- mands quickly, since a command in C is translated into a relatively small number of machine language commands, again making it appear similar to a low-level language. An example of a programming language with properties of both a compiler and interpreter is FORTH. Commands (or words, as they are called in FORTH) are executed in binary (machine language) form, as in a compiled language. However, each word is executed separately under control of the environment. In addition, new words can be defined as combinations of old words. These new words are then translated into machine language before they can be executed. This type of language, having some properties of both a compiler and an interpreter, is called an incremental compiler. The commands (words) are compiled one at a time, with new ones built on combinations of existing ones. Now we will examine a few popular programming languages in greater detail. We will start with Assembly language, the lowest level of programming languages commonly used. 13.1 Assembly Language Assembly language (or Assembler) is a compiled, low-level computer language. It is processor-dependent, since it basically translates the As- sembler's mnemonics directly into the commands a particular CPU un- 13.1 Assembly Language 255 derstands, on a one-to-one basis. These Assembler mnemonics are the instruction set for that processor. In addition, an Assembler provides commands that control the assembly process, handle initializations, allow the use of variables and labels, and control output. In the world of MS-DOS personal computers, the most popular Assembly language is Microsoft Macro Assembler, or MASM (also sold by IBM). As with most popular compilers, MASM is upgraded on a regular basis. Most of this discussion refers to version 5.0 or later, which has simplified the use of certain directives and includes support for in- structions available only on 80286 and 80386 CPUs. - eBook - PDF
C++ Programming
From Problem Analysis to Program Design
- D. Malik(Author)
- 2017(Publication Date)
- Cengage Learning EMEA(Publisher)
Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 1 Processing a C++ Program | 9 language. To execute on a computer, these C11 instructions first need to be translated into machine language. A program called a compiler translates instructions written in high-level languages into machine code. Compiler: A program that translates instructions written in a high-level language into the equivalent machine language. Processing a C11 Program In the previous sections, we discussed machine language and high-level languages and showed a C11 statement. Because a computer can understand only machine language, you are ready to review the steps required to process a program written in C11. Consider the following C11 program: #include using namespace std; int main() { cout << "My first C++ program." << endl; return 0; } At this point, you need not be too concerned with the details of this program. How- ever, if you run (execute) this program, it will display the following line on the screen: My first C++ program. Recall that a computer can understand only machine language. Therefore, in order to run this program successfully, the code must first be translated into machine language. In this section, we review the steps required to execute programs written in C11. The following steps, as shown in Figure 1-2, are necessary to process a C11 program. 1. You use a text editor to create a C11 program following the rules, or syntax, of the high-level language. This program is called the source code, or source program. The program must be saved in a text file that has the extension .cpp. For example, if you saved the preceding program in the file named FirstCPPProgram, then its complete name is FirstCPPProgram.cpp. Source program: A program written in a high-level language. 2. The C11 program given in the preceding section contains the state- ment #include . - Martin Oliver Steinhauser(Author)
- 2012(Publication Date)
- De Gruyter(Publisher)
Section 2.1 Introduction 95 1. Intermediate code generation. Here, the source code is translated into an “intermediate” language. In Figure 2.4 a so-called three-address-code is used, which resembles assembly (machine lan-guage). This code is a sequence of commands, where each command has at most three operands and one operator (*,+,-,. . . ), besides the equal sign, for example, temp1 = intoDouble(10) /* transform int to double */ temp2 = id3 * temp1 temp3 = id2 * temp2 id1 = temp3 Variables temp1 , temp2 , and temp3 are temporary names for memory addresses (registers) which can be quickly accessed by the CPU. The advantage of interme-diate code is, that it can be re-used in case one wants to write compilers for several different languages. 2. Code optimizer. The generated intermediate code is improved by removing redundant commands. In our example, one can reduce the above four lines of code to just two: temp1 = id3 * 10.0 id1 = id2 + temp1 3. Code generator. Finally, the code generator translates the intermediate code into machine code of the respective CPU, as shown in Figure 2.4 with pseudo assembly code: MOVF id3, R2; load contents of register id3 into register R2 MULF #10.0, R2; multiply content of register R2 with 10.0 MOVF id2, R1; load content of id2 into register R1 ADDF R2, R1; add the content of R1 to the content of R2 MOVF R1, id1; store the content of R1 in register id1 Besides these major tasks, a compiler has the following two additional tasks: Management of the symbol table. The symbol table is a central data structure, that lists all names, data, types and attributes of all identifiers in the source code. Exception handling. All possible errors have associated error codes and messages. After most errors, the compiler may continue to find more errors. 96 Chapter 2 Scientific Computing in C Editing files The first obstacle a person is confronted with when programming is the editing en-vironment.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.








