public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Rhys Ulerich <rhys.ulerich@gmail.com>
To: Patrick Alken <patrick.alken@colorado.edu>
Cc: gsl-discuss@sourceware.org
Subject: Re: increment a single element of matrix/vector
Date: Tue, 28 Jan 2014 21:16:00 -0000	[thread overview]
Message-ID: <CAKDqugRbqu-jsBTpzQ-rKFXXnZyp6sUqf2LVgU8M9p-SawxKjw@mail.gmail.com> (raw)
In-Reply-To: <52E816F8.9050405@colorado.edu>

>>>> *gsl_vector_ptr(v, i) += x

>> *(gsl_vector_ptr(v, i)) += x;

Why the extra parens?  They hurt nothing, but the former statement
without them works just fine for me.  Unless I'm mistaken, the
function application happens before the dereference.  And the
dereference is much, much higher than anything like += or *= that the
user might want.

>> This could lead to trouble so its probably better to have a function
>> which does range checking, etc.

There is range checking in gsl_vector_ptr, so long as someone doesn't
start doing pointer arithmetic on its result.

Lastly, the pointer-based solution is nicely general: *(i > j ?
gsl_vector_ptr(v, i) : gsl_vector_ptr(j)) += 1

- Rhys

  reply	other threads:[~2014-01-28 21:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-27 23:47 Patrick Alken
2014-01-28  2:08 ` Rhys Ulerich
2014-01-28  2:15   ` Rhys Ulerich
2014-01-28  3:06     ` Patrick Alken
2014-01-28 20:45       ` Patrick Alken
2014-01-28 21:16         ` Rhys Ulerich [this message]
2014-01-28 21:26           ` Patrick Alken

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=CAKDqugRbqu-jsBTpzQ-rKFXXnZyp6sUqf2LVgU8M9p-SawxKjw@mail.gmail.com \
    --to=rhys.ulerich@gmail.com \
    --cc=gsl-discuss@sourceware.org \
    --cc=patrick.alken@colorado.edu \
    /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).