MAINSAIL Language Manual, Section 32.23

previous   next   top   contents   index   framed top   this page unframed


32.23. clear

Figure 32–20. clear (GENERIC)
$BUILTIN
PROCEDURE   clear       (ADDRESS dst;
                         
INTEGER n);

$BUILTIN
PROCEDURE   clear       (CHARADR dst;
                         
INTEGER n);

$BUILTIN
PROCEDURE   clear       (ADDRESS dst;
                         
LONG INTEGER n);

$BUILTIN
PROCEDURE   clear       (CHARADR dst;
                         
LONG INTEGER n);

PROCEDURE   clear       (POINTER p);

PROCEDURE   clear       (ARRAY dst;
                         
OPTIONAL INTEGER n);

PROCEDURE   clear       (ARRAY dst;
                         
OPTIONAL LONG INTEGER n);

$BUILTIN
SPECIAL
PROCEDURE   clear       ($REFERENCE r);

clear is used to clear storage units, characters, a record, a data section, or an ARRAY.

The ADDRESS forms of clear set the contents of n storage units starting with dst to Zero. No particular alignment requirement is imposed on dst.

The CHARADR forms of clear set the n character units starting with dst to the character code 0.

The effect of the ADDRESS and CHARADR forms of clear is undefined if dst is Zero or if any of the memory to be cleared has not been properly allocated.

The POINTER form of clear clears the dynamic record or data section pointed to by p; nothing happens if p is NULLPOINTER. Each field of the record pointed to by p is set to Zero. Clearing a data section has the effect of clearing the interface, outer, and own variables. Implicit MODULE POINTERs and shared variables are not cleared (see Sections 11.9 and 6.5).

The dynamic ARRAY forms of clear set the first n elements of the ARRAY dst to Zero (nothing happens if dst is Zero). n is determined as follows:

m := IF NOT n .MAX 0 THEN number of elements in ARRAY
     
ELSE n MIN number of elements in ARRAY

If n is Zero in an ADDRESS or CHARADR form of clear or negative in any form of clear, nothing is cleared.

The untyped reference form of clear can be used to clear an inplace record or inplace ARRAY; the entire content of the inplace object is cleared. The argument to this form of clear cannot itself be an untyped reference.

A garbage collection cannot occur during a call to clear unless the object to be cleared is a data section.

Example 32–21. Use of clear for a Dynamic ARRAY
INTEGER i;
INTEGER ARRAY(0 TO 1000) ary;
...
FOR i := 0 UPTO 1000 DO ary[i] := 0;

could be written as clear(ary)


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Section 32.23