From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119680 invoked by alias); 7 Apr 2016 13:38:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 119640 invoked by uid 89); 7 Apr 2016 13:38:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=assurance, risk X-HELO: usplmg21.ericsson.net Received: from usplmg21.ericsson.net (HELO usplmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 07 Apr 2016 13:38:43 +0000 Received: from EUSAAHC008.ericsson.se (Unknown_Domain [147.117.188.96]) by usplmg21.ericsson.net (Symantec Mail Security) with SMTP id BB.9A.22441.BB266075; Thu, 7 Apr 2016 15:38:03 +0200 (CEST) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.98) with Microsoft SMTP Server id 14.3.248.2; Thu, 7 Apr 2016 09:38:41 -0400 Subject: Re: [PATCH] value: Make accessor methods' parameters const-correct To: Pedro Alves , Martin Galvan , , References: <1459974933-616-1-git-send-email-martin.galvan@tallertechnologies.com> <57059D83.2010403@redhat.com> From: Simon Marchi Message-ID: <570662E0.1020500@ericsson.com> Date: Thu, 07 Apr 2016 13:38:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <57059D83.2010403@redhat.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00151.txt.bz2 On 16-04-06 07:36 PM, Pedro Alves wrote: > On 04/06/2016 09:35 PM, Martin Galvan wrote: >> I did a quick pass over value.c and value.h and made some of the accessor methods' >> parameters const-correct. Besides the obvious benefits, this is required if we >> want to use them on values that are already declared as const (such as the parameters >> to lval_funcs). I also const-ified some of the pass-by-value parameters; while >> they're not as important it's still nice to have them like that. > > Thanks for doing this. > > Const on pointer parameters is certainly useful. But since you asked > me [ :-) ], I'm on the "const on value params is mostly useless > clutter" camp. It's something you don't see many style guides requiring, > and it's something gdb hasn't been doing either. > > So personally I'd prefer a patch without those bits. > >> >> There's probably a lot more stuff that can be made const, here and elsewhere. >> >> I have write access and copyright assignment. Ok to commit? > Thanks, > Pedro Alves > I agree with Pedro. The main value of const I think is to give the assurance to the callers that the function won't change anything that is passed by reference, preventing side-effects. For arguments passed by value, we already know that. One could argue that it could prevent assigning to it by mistake. But I'd say that that risk is very low, especially in short/obvious functions like this. If the function was longer and more complicated, then maybe it could help the reader understand that this argument/variable never changes value. If that became the standard coding style everywhere in the code, it would make things quite heavy. And to be pedantic, if you want to make all arguments const you should also do this :) -set_value_bitpos (struct value *value, int bit) +set_value_bitpos (struct value *const value, const int bit) Simon