public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: John D Lamb <J.D.Lamb@btinternet.com>
To: gsl-discuss@sourceware.org
Subject: Re: const gsl_vector *
Date: Tue, 19 Aug 2014 09:19:00 -0000	[thread overview]
Message-ID: <53F3164F.50508@btinternet.com> (raw)
In-Reply-To: <53EAAB60.3080701@lanl.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

  reply	other threads:[~2014-08-19  9:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13  0:03 Gerard Jungman
2014-08-19  9:19 ` John D Lamb [this message]
2014-08-19 22:28   ` Patrick Alken
2014-08-20  6:37     ` John D Lamb
2014-08-19 22:33   ` Patrick Alken
2014-08-27  0:08     ` Gerard Jungman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53F3164F.50508@btinternet.com \
    --to=j.d.lamb@btinternet.com \
    --cc=gsl-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).