Reference: Difference between revisions

no edit summary
m (Syntax)
No edit summary
 
Line 10:
 
Referential semantics is exposed to the '''aliasing problem'''. The issue arises when the same object is passed into a subprogram, or becomes otherwise accessible through two distinct names or reference objects. In this case updating the object through one reference would implicitly change the target of another. So in presence of aliasing the program semantics might become dependent on referential or value semantics of the object, thus on an implementation. Example:
<lang ada>
procedure Inc (X : in out Integer; Y : Integer) is
begin
Line 19:
begin
Inc (Value, Value); -- Value is aliased as X and Y in Inc
</adalang>
Here, when Integer is passed by value, the result will be 3, when it were passed by reference it would be 4. Aliasing is harmless when objects are immutable.