previous next top contents index framed top this page unframed
Figure 32–53. copy (GENERIC)
| $BUILTIN PROCEDURE copy (ADDRESS src,dst; INTEGER n); $BUILTIN PROCEDURE copy (CHARADR src,dst; INTEGER n); $BUILTIN PROCEDURE copy (ADDRESS src,dst; LONG INTEGER n); $BUILTIN PROCEDURE copy (CHARADR src,dst; LONG INTEGER n); PROCEDURE copy (POINTER src,dst); PROCEDURE copy (ARRAY src,dst; OPTIONAL INTEGER n); PROCEDURE copy (ARRAY src,dst; OPTIONAL LONG INTEGER n); |
copy is used to copy storage units, characters, a dynamic record, or a dynamic ARRAY. (The assignment operator may be used to copy inplace records and inplace ARRAYs; see Sections 10.7.2 and 12.9.1).
The POINTER form of copy copies the record pointed to by src to the record pointed to by dst. The number of storage units copied is determined by the smaller of the two records. The effect is undefined if src and dst are not CLASS compatible. It is an error if src or dst is a POINTER to a data section.
The ARRAY forms of copy copy the first m elements of the src ARRAY to the first m elements of the dst ARRAY. The two ARRAYs must be of the same data type. m is determined as follows:
m1 := elementsInSrcArray MIN elementsInDstArray;
m := IF NOT n .MAX 0(L) THEN m1 ELSE n MIN m1;
The ADDRESS forms of copy copy n storage units from memory starting at src to memory starting at dst. No particular alignment requirements are imposed on src or dst.
The CHARADR forms of copy copy n characters from memory starting at src to memory starting at dst.
Neither src nor dst may be Zero for any form of copy. For the POINTER and ARRAY forms, this situation generates an error; for the ADDRESS and CHARADR forms, the result is undefined.
If n is Zero or negative in any form of copy, no data movement takes place.
In the ADDRESS and CHARADR forms, the effect is undefined if the source and destination areas of memory overlap.
A garbage collection cannot occur during a call to copy.
Example 32–54. Use of copy
| CLASS c (BITS b,c; STRING s); POINTER(c) p,q; p := new(c); q := new(c); ... copy(q,p); # does same as: # p.b := q.b; p.c := q.c; p.s := q.s; |
MAINSAIL Language Manual, Section 32.54