Copying a general size vector (original) (raw)
Next: General size vector addition Up: General size vectors Previous: Accessing the elements of Contents
Copying a general size vector
To copy a vector
to another vector
, both vectors must have been created, and
should be filled with values.
can be created with arbitrary initial size (for instance zero), since Gandalf will if necessary reallocate
to the same size as
if necessary. So for instance the following code is perfectly valid:
Gan_Vector vx, vy; /* declare vectors x & y */
gan_vec_form ( &vx, 0 ); /* create vector x */
gan_vec_form ( &vy, 0 ); /* create vector y */
gan_vec_fill_va ( &vx, 5, 11.0, 9.0, 7.0, 5.0, 3.0 ); /* reallocate & initialise x */
gan_vec_copy_q ( &vx, &vy ); /* set y = x, reallocating y */The last two lines reallocate first
and then
, because both were created with zero size. Note that
may have previously been filled with other values, which are now lost.
There is also a version that creates a copy of a vector from scratch:
Gan_Vector *pvy; /* declare vector y */
pvy = gan_vec_copy_s ( &vx ); /* create y and set y = x */Error detection: The vector copy routines return NULL and invoke the Gandalf error handler upon failure.
2006-03-17