Pointers vs references for out and inout parameters
Mon May 21 00:20:00 GMT 2018
On 2018-03-06 09:47 AM, Simon Marchi wrote:
> When writing a function that modifies an object, we have two
> declaration: void do_something (object &obj);
> call: do_something (obj);
> 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 , I think it makes sense.
> I would suggest to add it to our C++ coding standards wiki page .
> Any objection?
I interpret the silence as an agreement :), so I have now done this.
More information about the Gdb-patches