This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: gsl_vector_const_view: pointer to constant or constant pointer
- From: Fleur Kelpin <fleur at bio dot vu dot nl>
- To: Brian Gough <bjg at network-theory dot co dot uk>
- Cc: gsl-discuss at sources dot redhat dot com
- Date: Mon, 12 Aug 2002 21:05:15 +0200 (MEST)
- Subject: Re: gsl_vector_const_view: pointer to constant or constant pointer
> It's not possible to initialise the struct element with this form in
> ANSI C (although it is possible in gcc). This is why the const'ing is
> done at a higher level in a wrapper.
I found this out later, when I tried and considered some of the
alternatives and I think I discovered some of the the reasons for the gsl
vector setup.
Is it correct that the definition
typedef struct
{
const gsl_vector *vector;
} gsl_vector_const_view;
would have the advantage that gsl_vector_const_view s can be initialized
and reassigned but the disadvantage that memory is allocated for the
vectors in the views and will need to be freed after use?
I ended up changing to non-const gsl_vector_view and casting the const
from my arrays, as Joohnas Pihlaja suggested. The other solution I could
think of was sticking to const double * s and creating the
gsl_vector_const_view only last minute when I need it.