This is the mail archive of the
gsl-discuss@sourceware.org
mailing list for the GSL project.
Re: const gsl_vector *
- From: John D Lamb <J dot D dot Lamb at btinternet dot com>
- To: gsl-discuss at sourceware dot org
- Date: Tue, 19 Aug 2014 10:18:07 +0100
- Subject: Re: const gsl_vector *
- Authentication-results: sourceware.org; auth=none
- References: <53EAAB60 dot 3080701 at lanl dot gov>
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