Pointers are references to a memory locations. Like any other variable, you must declare a pointer before using it. Pointers are useful to improve performance or to create input/output parameters.

Implementation

Pointers are available only in Level-1 compilers. Other compilers do not use pointers. Instead we rename pointers to references. A similar paradigm shift is used in Java, Python, Go and other high level languages. We are not different and we follow the pack so you can learn the natural order of things in programming.

Pointer notation

The general form of a pointer declaration is using “at” symbol “@”. We have chosen this symbol to suggest the memory address location. Using pointers with @type we can define “pointer” variables. We can use unary operator ? to extract address of a variable:

let
  n: Integer;
  p: @Integer; !define a pointer
do
  p := ?n; !transfer address of "n" to "p"
end do;

Primary usage

Assign operator “:=” works “by value“. It is making a full copy of the original value. For composite types: {vector, matrix, record, tuple, string} the assign operator can create large “data movement” that can be avoided by using pointers.

When we use pointers to {@vector, @matrix, @record, @tuple, @string} The memory location is shared using “?=” operator” that is address of variable. This will transfer address into a pointer and this is much faster.

You need to login to view the rest of the content. Please . Not a Member? Join Us