5 Dec 2006 02:21
Gsl_vector_const_view
Leibs, Jeremy <Jeremy.Leibs <at> ngc.com>
2006-12-05 01:21:09 GMT
2006-12-05 01:21:09 GMT
I think the way const's are dealt with in gsl_vector_views (and matrix
views) is possibly flawed. If it's not flawed I'm missing something
fundamental in the way they are intended to be used.
The gsl_vector_const_view is currently just implemented as a const
gsl_vector_view (which I'm sure was the easiest way to do it that works
in most cases). While this forces the vector member to be const, it
means that the block pointer becomes a const pointer to non-const data
("gsl_block* const block" when I think we want "const gsl_block*
block"?). This means there is nothing actually protecting the data
itself other than the const wrapper being interpreted by functions that
are designed to take gsl_vector*s as inputs.
As a demonstration of the problem consider:
const double data1[] = {1, 2, 3, 4};
const double* data2;
data2 = data1; //This is appropriately legal
// Clearly these will not work:
// data1[0] = 10;
// data2[0] = 10;
gsl_vector_const_view A = gsl_vector_const_view_array(data2, 4);
// constness keeps this from working:
// gsl_vector_set(&A.vector, 0, 10);
(Continue reading)
RSS Feed