This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gsl_vector_const_view: pointer to constant or constant pointer


Hi all!

Compiling

#include <gsl/gsl_vector.h>

int main()
{
  const double x[]={1,2,3,4};
  gsl_vector_const_view xview;
  xview = gsl_vector_const_view_array(x,4);
  return 0;
}

gives a
warning: assignment of read-only variable `xview'
since (in gsl_vector_double.h) gsl_vector_const_view is declared as a
constant pointer to a _gsl_vector_const_view:

typedef struct
{
  gsl_vector vector;
} _gsl_vector_const_view;

typedef const _gsl_vector_const_view gsl_vector_const_view;
        ^^^^^

Is this as intended? The manual states that 'Vector views can be defined
for both constant and non-constant vectors, using separate types that
preserve constness'. It seems to me that the point of the special const
type is to prevent changes to the vector viewed, not also changes to the
pointer to the view. I could easily prevent such changes to the pointer
myself when necessary, declaring

const gsl_vector_const_view xview;

But currently you cannot choose!

Am I missing something or can/could/should this be fixed?
(I think this can be done by moving the const inside the struct:

typedef struct
{
  const gsl_vector vector;
} _gsl_vector_const_view;

typedef _gsl_vector_const_view gsl_vector_const_view;

)

Greetings,
Fleur


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]