next up previous contents
Next: Accessing the elements of Up: General size vectors Previous: Adjusting the size of   Contents

Filling a general size vector with values

To fill a vector with values, create the vector and then use the routine gan_vec_fill_va(). An example is
      gan_vec_fill_va ( &vx, 6, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 );
which sets vector vx to have size 6, and sets the six elements to the values one to six.

To fill a vector with a constant value, you can use

      gan_vec_fill_const_q ( &vx, 4, 3.0 );
which sets the size of vx to four elements, all of which are set to three. This function is also available in a form which allocates and fills a vector from scratch:
      Gan_Vector *pvx;

      pvx = gan_vec_fill_const_s ( 4, 3.0 );
There are special macro routines for setting a vector to zero:
      gan_vec_fill_zero_q ( &vx, 4 ); /* OR */
      pvx = gan_vec_fill_zero_s(4);

Error detection: NULL is returned and the error handler is invoked on failure. The most likely failure mode is failing to reallocate the vector data when the size of the vector is changed, i.e. failure of a call to realloc().