This is the mail archive of the
mailing list for the GDB project.
Re: [PATCH] value: Make accessor methods' parameters const-correct
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: Pedro Alves <palves at redhat dot com>, Martin Galvan <martin dot galvan at tallertechnologies dot com>, <gdb-patches at sourceware dot org>, <tom at tromey dot com>
- Date: Thu, 7 Apr 2016 09:38:40 -0400
- Subject: Re: [PATCH] value: Make accessor methods' parameters const-correct
- Authentication-results: sourceware.org; auth=none
- References: <1459974933-616-1-git-send-email-martin dot galvan at tallertechnologies dot com> <57059D83 dot 2010403 at redhat dot com>
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?
> 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)