Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the correct term for returning something as an out parameter?

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

like image 499
Armen Tsirunyan Avatar asked Feb 06 '12 10:02

Armen Tsirunyan


People also ask

What is an out parameter?

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.

What is the difference between return value and out parameter?

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.

What is in parameter and out parameter?

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.

What is it called when a parameter is passed to the method?

When a parameter is passed to the method, it is called an argument.


2 Answers

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

like image 144
Fred Foo Avatar answered Nov 09 '22 08:11

Fred Foo


In simplest words:

Function SomeFunc() can modify parameters xxx(std::string) and yyy(char) and returns success or failure (bool).

like image 24
iammilind Avatar answered Nov 09 '22 06:11

iammilind