Take from wikipedia, aliasing is defined as accessing a data location through different names.
Also taken from wikipedia, indirection is defined as referencing something “using a name, reference, or container instead of the value itself”. Am I missing something here – Are these two one and the same? If not, how are they different?
0
Aliasing is when there are several names (or expressions) to designate the same object.
Indirection is when there are additional steps to reach the object.
Both are usually present, but not always. As an example of aliasing without indirection
namespace X {
int x;
}
namespace Y {
using namespace X;
}
X::x
and Y::x
are two different names for the same objects, there are aliases and no indirection is present.
As an example of indirection without aliases
int* p = new int;
To access the allocated object, you have to go through p with *p
, the access is indirect and there are no aliases.
But indirection is usually present when there are aliases (visibly with q=p
, *p
and *q
are aliases, or more or less hidden in the implementation or the language rules, see references in C++ or with the fact that a[i]
and a[j]
which are aliases if i==j
.)
To my understanding, “indirection” is a very general term decribing all kind of forms of using alternate names, references, containers, wrappers, and so on – every kind of non-direct access. Aliasing is IMHO a special case of indirection, because aliasing is specifically about using different names, nothing else.
For example, in programming, accessing a library or a device through a public interface may allow to add some kind of indirection “behind the scenes”, within the library, but without any visible change in the API (or names) from the viewpoint of a user of that library. For example, think of a network library which allows to activate or deactivate a “proxy”. The public interface keeps staying the same, so there is no “aliasing” here, but its is indeed a form of indirection.