Wolmer’s Trust High School for Girls

CAPE COMPUTER SCIENCE

 

Grades:  Upper and Lower Six                           Teacher: Mrs. McCallum-Rodney

 

ROLE OF PREPROCESSORS – LINKERS

 

INTRODUCTION

In computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers. The amount and kind of processing done depends on the nature of the preprocessor; some preprocessors are only capable of performing relatively simple textual substitutions and macro expansions, while others have the power of fully-fledged programming languages.

A common example from computer programming is the processing performed on source code before the next step of compilation. In some computer languages (e.g., C) there is a phase of translation known as preprocessing.

Lexical pre-processors

Lexical preprocessors are the lowest-level of preprocessors, insofar as they only require lexical analysis, that is, they operate on the source text, prior to any parsing, by performing simple substitution of tokenized character sequences for other tokenized character sequences, according to user-defined rules. They typically perform macro substitution, textual inclusion of other files, and conditional compilation or inclusion.

Pre-processing in C/C++

The most widely used lexical preprocessor is CPP, the C preprocessor, used pervasively in C and its descendant, C++. This preprocessor is used to provide the usual set of preprocessing services.

Inclusion

The most common use of the C preprocessor is the

#include "..."

or

#include <...>

directive, which copies the full content of a file into the current file, at the point at which the directive occurs. These files usually (almost always) contain interface definitions for various library functions and data types, which must be included before they can be used; thus, the #include directive usually appears at the head of the file. The files so included are called "header files" for this reason. Some examples include <math.h> and <stdio.h> from the standard C library, providing mathematical and input/output functions, respectively.

While this use of a preprocessor for code reuse is simple, it is also slow, rather inefficient and requires the additional use of conditional compilation to avoid multiple inclusions of a given header file.

WHAT ARE LINKERS?

In computer science, a linker or link editor is a program that takes one or more objects generated by compilers and assembles them into a single executable program.

The linker's job is to resolve references to undefined symbols by finding out which other object defines a symbol in question, and replacing placeholders with the symbol's address.

Linkers can take objects from a collection called a library. Some linkers do not include the whole library in the output; they only include its symbols that are referenced from other object files or libraries. Libraries exist for diverse purposes, and one or more system libraries are usually linked in by default.

The linker also takes care of arranging the objects in a program's address space. This may involve relocating code that assumes a specific base address to another base. Since a compiler seldom knows where an object will reside, it often assumes a fixed base location (for example, zero). Relocating machine code may involve re-targeting of absolute jumps, loads and stores.

The executable output by the linker may need another relocation pass when it is finally loaded into memory (just before execution). This pass is usually omitted on hardware offering virtual memory — every program is put into its own address space, so there is no conflict even if all programs load at the same base address. This pass may also be omitted if the executable is a position independent executable.

 

 

Make a Free Website with Yola.