I hope this question is on topic.
I was doing code review and stumbled upon the following function:
bool SomeFunc(std::string& o_xxx, char& o_yyy);
This function is used to retrieve the values of xxx
and yyy
of some class by means of out parameters.
The comments (which are later used for auto-documentation) say:
... this function returns by reference the [xxx] and [yyy]...
Obviously the function returns a boolean value indicating success or failure. So the sentence above need to be rephrased. But how? What's the correct term (if any) for returning something, as it were, by means of an out parameter, or, in other words, populating an argument passed by reference?
The question is tagged language agnostic, because it's not C++ specific. But it's also tagged C++ because the example is in C++.
The out parameter in C# is used to pass arguments to methods by reference. It differs from the ref keyword in that it does not require parameter variables to be initialized before they are passed to a method. The out keyword must be explicitly declared in the method's definition as well as in the calling method.
Out is used where your method needs to return multiple values. If you use return, then the data is first written to the methods stack and then in the calling method's. While in case of out, it is directly written to the calling methods stack.
The in, ref, and out Modifiersref is used to state that the parameter passed may be modified by the method. in is used to state that the parameter passed cannot be modified by the method. out is used to state that the parameter passed must be modified by the method.
When a parameter is passed to the method, it is called an argument.
"Upon success, SomeFunc
stores in o_xxx
and o_yyy
the values ..."; stores in is how the Linux manpage strtoul(3)
describes what that function does with its endptr
argument.
Though I've also heard the phrase "return in" often enough with reference-typed out parameters.
In simplest words:
Function
SomeFunc()
can modify parametersxxx(std::string)
andyyy(char)
and returns success or failure (bool
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With