Pointers and references: Difference between revisions

No edit summary
Line 2:
 
In this task, the goal is to desmonstrate common operations on pointers and references.
 
==[[Ada]]==
[[Category:Ada]]
Ada does not have pointers, only access types.
 
Create a pool specific access type for an integer
type Int_Access is access Integer;
Int_Acc : Int_Access := new Integer(5);
Create a general access type for an integer
type Int_Ptr is access all Integer;
Ref : Int_Ptr;
Var : aliased Integer := 3;
Ref := Var'access;
Ada does not provide pointer arithmetic, but does allow evaluation of the address
Var : Integer;
Var_Address : Address := Var'address;
Addresses support operations of comparison, addition, and subtraction
Ada also supports conversion between address types and a pre-defined subtype of
Integer named Integer_Address. This accomodates the conversion to a linear
addressing of any hardware address scheme including address:offset used in
the 8086 processor.
 
Ada allows the specification of a starting address for any object
 
-- Demonstrate the overlay of one object on another
A : Integer;
B : Integer;
for B'address use A'address;
-- A and B start at the same address
 
==[[C plus plus|C++]]==
Anonymous user