From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2132 invoked by alias); 28 Jan 2014 21:16:35 -0000 Mailing-List: contact gsl-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gsl-discuss-owner@sourceware.org Received: (qmail 2112 invoked by uid 89); 28 Jan 2014 21:16:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f47.google.com Received: from mail-wg0-f47.google.com (HELO mail-wg0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 28 Jan 2014 21:16:34 +0000 Received: by mail-wg0-f47.google.com with SMTP id m15so1869436wgh.2 for ; Tue, 28 Jan 2014 13:16:30 -0800 (PST) X-Received: by 10.194.76.134 with SMTP id k6mr2433609wjw.32.1390943790614; Tue, 28 Jan 2014 13:16:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.60.137 with HTTP; Tue, 28 Jan 2014 13:16:09 -0800 (PST) In-Reply-To: <52E816F8.9050405@colorado.edu> References: <52E6EFF3.1000808@colorado.edu> <52E71EC5.800@colorado.edu> <52E816F8.9050405@colorado.edu> From: Rhys Ulerich Date: Tue, 28 Jan 2014 21:16:00 -0000 Message-ID: Subject: Re: increment a single element of matrix/vector To: Patrick Alken Cc: gsl-discuss@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-SW-Source: 2014-q1/txt/msg00022.txt.bz2 >>>> *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