public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* gsl_vector_const_view: pointer to constant or constant pointer
@ 2002-08-09 21:20 Fleur Kelpin
  2002-08-09 23:29 ` Fleur Kelpin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Fleur Kelpin @ 2002-08-09 21:20 UTC (permalink / raw)
  To: gsl-discuss

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-08-13 18:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-09 21:20 gsl_vector_const_view: pointer to constant or constant pointer Fleur Kelpin
2002-08-09 23:29 ` Fleur Kelpin
2002-08-11  7:46 ` M Joonas Pihlaja
2002-08-11 15:32 ` Brian Gough
2002-08-12 12:05   ` Fleur Kelpin
2002-08-13 11:14     ` Brian Gough

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).