MAINSAIL Language Manual, Section 33.29

previous   next   top   contents   index   framed top   this page unframed


33.29. displacement

Figure 33–29. displacement (GENERIC)
$BUILTIN
INTEGER
PROCEDURE   displacement
                        (
ADDRESS a,b);

$BUILTIN
INTEGER
PROCEDURE   displacement
                        (
CHARADR a,b);

displacement computes the distance between two ADDRESSes or CHARADRs.

The ADDRESS form returns the number of storage units from ADDRESS a to ADDRESS b.

The CHARADR form returns the number of character units from CHARADR a to CHARADR b.

If a is beyond b, the result is negative. If there is a possibility that the distance is larger than can be represented as an INTEGER, lDisplacement should be used; the use of displacement when the distance between a and b is larger than can be represented as an INTEGER is undefined.

Example 33–30. Use of displacement
INTEGER i;
ADDRESS a,b;
INTEGER ARRAY(1 TO 100) ary;
...
IF NOT ary THEN new(ary);
a := $adrOfFirstElement(ary);
b := a;
FOR i := 1 UPTO 100 DO read(b,ary[i]);
i := displacement(a,b);

i = 100 * size(integerCode)


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Section 33.29