This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Pointers vs references for out and inout parameters
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: gdb-patches at sourceware dot org
- Date: Tue, 06 Mar 2018 09:47:45 -0500
- Subject: Pointers vs references for out and inout parameters
- Authentication-results: sourceware.org; auth=none
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