From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9210 invoked by alias); 28 Jan 2014 21:26:28 -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 9201 invoked by uid 89); 28 Jan 2014 21:26:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: ipmx5.colorado.edu Received: from ipmx5.colorado.edu (HELO ipmx5.colorado.edu) (128.138.128.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Jan 2014 21:26:27 +0000 From: Patrick Alken Received: from bonanza.ngdc.noaa.gov ([140.172.179.41]) by smtp.colorado.edu with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Jan 2014 14:26:26 -0700 Message-ID: <52E82081.3030107@colorado.edu> Date: Tue, 28 Jan 2014 21:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Rhys Ulerich CC: "gsl-discuss@sourceware.org" Subject: Re: increment a single element of matrix/vector References: <52E6EFF3.1000808@colorado.edu> <52E71EC5.800@colorado.edu> <52E816F8.9050405@colorado.edu> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2014-q1/txt/msg00023.txt.bz2 On 01/28/2014 02:16 PM, Rhys Ulerich wrote: >>>>> *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. Yes sorry I didn't see the * the first time I read that >>> 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 Hmm ok you convinced me, I'll reverse those last few commits