Lesson 1

Ace your homework & exams now with Quizwiz!

What are the 4 Preprocessor Directives?

1.Macros 2.File Inclusion 3.Conditional Compilation 4.Other directives

Dynamic linking

Dynamic linking is performed at run time. This linking is accomplished by placing the name of a shareable library in the executable image. There is more chances of error and failure chances. It require less memory space as multiple program can share a single copy of the library.

Assembler

For every platform (Hardware + OS) we will have a assembler. They are not universal since for each platform we have one. The output of assembler is called object file. Its translates assembly language to machine code.

Macros

In C++ macros are always proceeded by #define. Macros are a piece of code which is given some name. Whenever this name is encountered by the preprocessor the preprocessor replaces the name with the actual piece of code. The '#define' directive is used to define a macro.

Symbol resolution

It associates each symbol reference with exactly one symbol definition .Every symbol have predefined task. (static linking)

Relocatable Machine Code

It can be loaded at any point and can be run. The address within the program will be in such a way that it will cooperate for the program movement.

Loader/Linker

It converts the relocatable code into absolute code and tries to run the program resulting in a running program or an error message (or sometimes both can happen). Linker loads a variety of object files into a single file to make it executable. Then loader loads it in memory and executes it.

Relocation

It relocate code and data section and modify symbol references to the relocated memory location. (static linking)

Assembly Language

Its neither in binary form nor high level. It is an intermediate state that is a combination of machine instructions and some other useful data needed for execution.

Static Linking

Linking is performed at both compile time, when the source code is translated into machine code and load time, when the program is loaded into memory by the loader. Linking is performed at the last step in compiling a program.

Intermediate Code Generator

Most compilers translate a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code specifically for the machine architecture and operating system that the code is being written for.

C/C++ Preprocessors

Preprocessor programs provide preprocessors directives which tell the compiler to preprocess the source code before compiling. All of these preprocessor directives begin with a '#' (hash) symbol. The '#' symbol indicates that, whatever statement start with #, is going to preprocessor program, and preprocessor program will execute this statement.

Semantic Analyzer

Semantic analysis performs semantic checks such as type checking (makes sure that mathematical operations are being performed on variables declared as int or float), or object binding (making sure that declarations match and function calls and types are correct), or definite assignment (requiring all local variables to be initialized before use), rejecting incorrect programs or issuing warnings. Semantic analysis logically follows the parsing phase, and logically precedes the code generation phase, though it is often possible to fold multiple phases into one pass over the code in a compiler implementation.

Linking and Libraries

The linker is a program in a system which helps to link a object modules of program into a single object file. It performs the process of linking. Linker are also called link editors. Linking is process of collecting and maintaining piece of code and data into a single file. Linker also link a particular module into system library. It takes object modules from assembler as input and forms an executable file as output for loader.

Compiling- Analysis Phase

The phase of the compiler splits the source code into tokens. A lexical token or simply token is a string with an assigned and thus identified meaning. It is structured as a pair consisting of a token name and an optional token value. Common token names are identifier: names the programmer chooses; keyword: names already in the programming language; separator (also known as punctuators): punctuation characters and paired-delimiters; operator: symbols that operate on arguments and produce results; literal: numeric, logical, textual, reference literals; comment: line, block.

Pre-Processor

The pre-processor removes all the directives and performs: file inclusion, macro-processing, performs conditional compilation as previously discussed

The Compile Process

The process then to take the preprocessed code and turn it into executable code is a bit more complex. Depending on who you are talking to the steps may be a called something a bit different - but the actual process is the same, we will take a brief look at the steps in the next several pages.

What's in a File?

There is nothing special about a file that contains computer source code. It is simply a text file that contains text written in a specific syntax that defines what language is being used.

Header File or Standard Files

These files contains definition of pre-defined functions like cout & cin, getline() etc. These files must be included for working with these functions. Different function are declared in different header files.

Absolute Machine Code

This is the executable file, based on the system architecture and operating system it is to run on.

Syntax Analyzer

This is the process of checking a string of symbols, created by the lexical analysis stage, to see how well the symbols are how they need to be. This is determined by the use of the rules of a formal grammar. For C++, as with any programming language, is a well defined syntax of the language, just as there is a defined syntax for all written languages.

File Inclusion

This type of preprocessor directive tells the compiler to include a file in the source code program. There are two types of files which can be included by the user in the program: Header File or Standard Files & User Defined Header Files

User Defined Header Files

Users have the ability define their own functions that are used across several files or projects. These files can be included into the source code as:#include "filename" where filename is the name of the actual file that contains the code.

High Level Language

refers to a programming language such as C++, Java, C#, etc. They are typically much easier for humans to read an understand than low level languages like machine code and assembly language.

Conditional Compilation

this type of preprocessor directives are type of directives which helps to compile a specific portion of the program or to skip compilation of some specific part of the program based on some conditions. This can be done with the help of several preprocessing commands #if, #ifdef, #ifndef, #if, #endif, #else and #elif. (#ifdef - is 'if defined', and #ifndef - is 'if not define')


Related study sets

MIS 140 Chapter 3 Homework question

View Set

Tropical climates: the ITCZ, Equatorial climate, Tropical wet and dry climate, tropical monsoon climate

View Set

Spanish Conjugation: Mirar - to look at - Present

View Set

WGU Operations and Supply Chain Management

View Set

Infancy and Childhood (Module 14)

View Set