public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Pointers vs references for out and inout parameters
@ 2018-03-06 14:47 Simon Marchi
  2018-05-21  0:20 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2018-03-06 14:47 UTC (permalink / raw)
  To: gdb-patches

When writing a function that modifies an object, we have two 
possibility:

declaration: void do_something (object &obj);
call: do_something (obj);

or

declaration: void do_something (object *obj);
call: do_something (&obj);

I don't think we ever ruled on which we preferred, and sometimes it's 
ambiguous during reviews which one we should use.  When reviewing one of 
Tom's patches a while ago, I suggested he uses a reference instead of a 
pointer.  His rationale for using a pointer was that it makes it more 
obvious at the call site that the object is going to be modified.

The Google C++ style guide forbids non-const reference arguments, pretty 
much for this reason [1], I think it makes sense.

I would suggest to add it to our C++ coding standards wiki page [2].

Any objection?

[1] 
https://google.github.io/styleguide/cppguide.html#Reference_Arguments
[2] 
https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#C.2B-.2B-_Usage

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Pointers vs references for out and inout parameters
  2018-03-06 14:47 Pointers vs references for out and inout parameters Simon Marchi
@ 2018-05-21  0:20 ` Simon Marchi
  2020-09-01 14:13   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2018-05-21  0:20 UTC (permalink / raw)
  To: gdb-patches

On 2018-03-06 09:47 AM, Simon Marchi wrote:
> When writing a function that modifies an object, we have two 
> possibility:
> 
> declaration: void do_something (object &obj);
> call: do_something (obj);
> 
> or
> 
> declaration: void do_something (object *obj);
> call: do_something (&obj);
> 
> I don't think we ever ruled on which we preferred, and sometimes it's 
> ambiguous during reviews which one we should use.  When reviewing one of 
> Tom's patches a while ago, I suggested he uses a reference instead of a 
> pointer.  His rationale for using a pointer was that it makes it more 
> obvious at the call site that the object is going to be modified.
> 
> The Google C++ style guide forbids non-const reference arguments, pretty 
> much for this reason [1], I think it makes sense.
> 
> I would suggest to add it to our C++ coding standards wiki page [2].
> 
> Any objection?
> 
> [1] 
> https://google.github.io/styleguide/cppguide.html#Reference_Arguments
> [2] 
> https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#C.2B-.2B-_Usage
> 
> Simon
> 

I interpret the silence as an agreement :), so I have now done this.

https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Avoid_non-const_reference_parameters.2C_use_pointers_instead

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Pointers vs references for out and inout parameters
  2018-05-21  0:20 ` Simon Marchi
@ 2020-09-01 14:13   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2020-09-01 14:13 UTC (permalink / raw)
  To: gdb-patches

On 2018-05-20 8:06 p.m., Simon Marchi wrote:
> On 2018-03-06 09:47 AM, Simon Marchi wrote:
>> When writing a function that modifies an object, we have two 
>> possibility:
>>
>> declaration: void do_something (object &obj);
>> call: do_something (obj);
>>
>> or
>>
>> declaration: void do_something (object *obj);
>> call: do_something (&obj);
>>
>> I don't think we ever ruled on which we preferred, and sometimes it's 
>> ambiguous during reviews which one we should use.  When reviewing one of 
>> Tom's patches a while ago, I suggested he uses a reference instead of a 
>> pointer.  His rationale for using a pointer was that it makes it more 
>> obvious at the call site that the object is going to be modified.
>>
>> The Google C++ style guide forbids non-const reference arguments, pretty 
>> much for this reason [1], I think it makes sense.
>>
>> I would suggest to add it to our C++ coding standards wiki page [2].
>>
>> Any objection?
>>
>> [1] 
>> https://google.github.io/styleguide/cppguide.html#Reference_Arguments
>> [2] 
>> https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#C.2B-.2B-_Usage
>>
>> Simon
>>
> 
> I interpret the silence as an agreement :), so I have now done this.
> 
> https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Avoid_non-const_reference_parameters.2C_use_pointers_instead
> 
> Simon
> 

FYI, I removed this rule from the wiki page, since it was not applied consistently anyway.  I'll just get used to it :).

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-01 14:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-06 14:47 Pointers vs references for out and inout parameters Simon Marchi
2018-05-21  0:20 ` Simon Marchi
2020-09-01 14:13   ` Simon Marchi

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).