4 ms·
I saw another commenter explain that it’s passed by reference, but I agree with you. The C++ Core Guidelines even mention that it’s better to use raw pointers (
by _gabe_ 2y ago
I saw another commenter explain that it’s passed by reference, but I agree with you. The C++ Core Guidelines even mention that it’s better to use raw pointers (or pass by value and return a value) in cases like this to make the intent clear.
https://isocpp.org/wiki/faq/references#call-by-reference https://isocpp.org/wiki/faq/references#call-by-reference
- cornstalks 2y agonit: I don't think the Core Guidelines actually suggests it's better. It's just "one style." There are pros and cons to both styles.
- nmeofthestate 2y agoA pointer parameter can be null and it doesn't make sense for this parameter to be null, so IMO a reference is the better choice here. A non-const reference is just as clear a signal that the parameter may be modified as a non-const pointer. If there's no modification const ref should be used.
- jdashg 2y agoIt's about clarity of intent at the call site. Passing by mutable ref looks like `foo`, same as passing by value, but passing mutability of a value by pointer is textually readably different: `&foo`. That's the purpose of the pass by pointer style. You could choose to textually "tag" passing by mutable ref by passing `&foo` but this can rub people the wrong way, just like chaining pointer outvars with `&out_foo`.
- jcelerier 2y agoIf you want clarity of intent define dummy in and out macros but please don't make clean reference-taking APIs a mess by turning them into pointers for no good reason
- deleted 2y ago[deleted]
- gpderetta 2y agoIn theory a from_char with an optional output parameter could be useful to validate that the next field is a number and/or discard it without needing to parse it; it might even be worth optimizing for that case.