Contents    Page-10    Prev    Next    Page+10    Index   

Aliasing

An alias is the creation of a second name for the same storage. This can create unexpected results and should generally be avoided.


Main:                foo(j, k): 
      i = 24;                   j = k / 4;
      foo(i, i);                k = k + 5;
      print i;                  print j, k;


Results:  Value:      j =  6, k = 29, i = 24
          Reference:  j = 11, k = 11, i = 11

Using call by reference, we have created three aliases i, j, and k that all refer to the same storage location.

Aliasing causes problems for compiler optimization by creating unexpected side-effects.