Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
Indirection

Indirection

Overview
In computer programming
Computer programming
Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language. The code may be a modification of an existing source or something completely new...

, indirection is the ability to reference something using a name, reference, or container instead of the value itself. The most common form of indirection is the act of manipulating a value through its memory address
Memory address
In computer science, a memory address is an identifier for a memory location, at which a computer program or a hardware device can store data and later retrieve it...

. For example, accessing a variable
Variable (programming)
In computer programming, a variable is a facility for storing data. The current value of the variable is the data actually stored in the variable. Depending on the programming language in question, the data stored in the variable can be intentionally altered during the program run. This is why it...

 through the use of a pointer. A stored pointer that exists to provide a reference to an object by double indirection is called an indirection node. In some older computer architectures, indirect words supported a variety of more-or-less complicated addressing mode
Addressing mode
Addressing modes are an aspect of the instruction set architecture in most central processing unit designs. The various addressing modes that are defined in a given instruction set architecture define how machine language instructions in that architecture identify the operand of each instruction...

s.

A famous aphorism
Aphorism
The word aphorism denotes an original thought, spoken or written in a laconic and easily memorable form....

 of David Wheeler goes: All problems in computer science can be solved by another level of indirection;
this is often deliberately mis-quoted with "abstraction layer
Abstraction layer
An abstraction layer is a way of hiding the implementation details of a particular set of functionality. Software models that use layers of abstraction include the OSI 7 Layer model for computer network protocols, the OpenGL graphics drawing library, and the byte stream input/output model...

" substituted for "level of indirection".
Discussion
Ask a question about 'Indirection'
Start a new discussion about 'Indirection'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
In computer programming
Computer programming
Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language. The code may be a modification of an existing source or something completely new...

, indirection is the ability to reference something using a name, reference, or container instead of the value itself. The most common form of indirection is the act of manipulating a value through its memory address
Memory address
In computer science, a memory address is an identifier for a memory location, at which a computer program or a hardware device can store data and later retrieve it...

. For example, accessing a variable
Variable (programming)
In computer programming, a variable is a facility for storing data. The current value of the variable is the data actually stored in the variable. Depending on the programming language in question, the data stored in the variable can be intentionally altered during the program run. This is why it...

 through the use of a pointer. A stored pointer that exists to provide a reference to an object by double indirection is called an indirection node. In some older computer architectures, indirect words supported a variety of more-or-less complicated addressing mode
Addressing mode
Addressing modes are an aspect of the instruction set architecture in most central processing unit designs. The various addressing modes that are defined in a given instruction set architecture define how machine language instructions in that architecture identify the operand of each instruction...

s.

A famous aphorism
Aphorism
The word aphorism denotes an original thought, spoken or written in a laconic and easily memorable form....

 of David Wheeler goes: All problems in computer science can be solved by another level of indirection;
this is often deliberately mis-quoted with "abstraction layer
Abstraction layer
An abstraction layer is a way of hiding the implementation details of a particular set of functionality. Software models that use layers of abstraction include the OSI 7 Layer model for computer network protocols, the OpenGL graphics drawing library, and the byte stream input/output model...

" substituted for "level of indirection". Kevlin Henney
Kevlin Henney
Kevlin Henney is an author who writes on the subject of computer programming in C and C++ for magazines such as the C/C++ Users Journal, Application Development Advisor, JavaSpektrum, C++ Report, Java Report, EXE, and Overload....

's corollary to this is, "...except for the problem of too many layers of indirection."

Object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

 makes use of indirection extensively, a simple example being dynamic dispatch
Dynamic dispatch
In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code at runtime. This is done to support the cases where the appropriate method cannot be determined at compile-time...

. Higher-level examples of indirection are the design pattern
Design pattern (computer science)
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many...

s of the proxy
Proxy pattern
In computer programming, the proxy pattern is a software design pattern.A proxy, in its most general form, is a class functioning as an interface to something else...

 and the proxy server
Proxy server
In computer networks, a proxy server is a server that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource, available from a different server...

. Delegation
Delegation (programming)
In object-oriented programming there are two related notions of delegation.* Most commonly, it refers to a programming language feature making use of the method lookup rules for dispatching so-called self-calls as defined by Lieberman in his 1986 paper "Using Prototypical Objects to Implement...

 is another classic example of an indirection pattern. In strongly typed interpreted language
Interpreted language
In computer programming an interpreted language is a programming language whose programs are translated to machine code at the time of execution and it's implementation often takes the form of an interpreter...

s with dynamic datatypes, most variable references require a level of indirection: first the type of the variable is checked for safety, and then the pointer to the actual value is dereferenced and acted on.

Recursive data types are usually implemented using indirection because otherwise if a value of a datatype can contain the entirety of another value of the same datatype, there is no limit to the size a value of this datatype could need.

When doing symbolic programming from a formal mathematical specification the use of indirection can be quite helpful. To start with a simple example the variables x, y and z in an equation such as z = square root (x squared + y squared) can refer to any number. One could imagine objects for various numbers and then x, y and z could point to the specific numbers being used for a particular problem. The simple example has its limitation as there are infinitely many real numbers. In various other parts of symbolic programming there are only so many symbols. So to move on to a more significant example, in logic the formula α can refer to any formula, so it could be β, γ, δ, ... or η→π, ς v σ,.... When set-builder notation
Set-builder notation
In set theory and its applications to logic, mathematics, and computer science, set-builder notation is a mathematical notation for describing a set by stating the properties that its members must satisfy...

 is employed the statement Δ={α} means the set of all formulae - so although the reference is to α there are two levels of indirection here, the first to the set of all α and then the second to a specific formula for each occurrence of α in the set Δ.

See also

  • Handle
    Handle (computing)
    In computer programming, a handle is a particular kind of smart pointer. Handles are used when an application references blocks of memory or objects managed by another system, such as a database or an operating system....

  • Pointer
  • Reference
    Reference (computer science)
    In computer science, a reference is a value that enables a program to directly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing that data is called dereferencing...