This is the mail archive of the gsl-discuss@sourceware.org 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]

Re: const gsl_vector *




On 13/08/14 01:03, Gerard Jungman wrote:
The constness of gsl_vector interfaces makes no sense. This is a
simple observation, but it seems to have escaped discussion for
over a decade. Consider the following code (file attached).

  #include <gsl/gsl_vector.h>

  void notwhatyouthink(const gsl_vector * v)
  {
    v->data[0] = 42.0;
  }

The goals:
   - const-correctness
   - no "doubling" of interfaces
   - an architecture where views are central
   - memory management factored out (allocation/deallocation)

Ideas?

I mainly use C++. But I think C now works so that you could use

gsl_vector* const v

in place of a

const gsl_vector* v

argument, and get the desired result.

I don’t know if there would be unintended consequences of rewriting the arguments of the GSL functions this way. I know that C can’t handle both of

int function( const gsl_vector* v );
int function( gsl_vector* const v );

in the same code. So it would need a rewrite.

One issue would be that if the code were rewritten any code that passed a const gsl_vector* argument would cause a compilation failure. The workaround might be to use a

gsl_vector const* const v

argument. But I don’t know if that would cause problems, for example with older compilers.

--
John D Lamb


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