Comment by jlarocco

5 years ago

It's wrong to call output parameters a "C/C++ trick" because the concept really has nothing to do with C, C++, buffer overruns, purity, or "other nastiness".

The idea is that the caller tells the function its calling where to store results, rather than returning the results as values.

For example, Ada and Pascal both have 'out' parameters:

    https://stackoverflow.com/questions/3003480/the-use-of-in-out-in-ada#3004067

    https://freepascal.org/docs-html/ref/refsu66.html#x182-20600014.4.3

    http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-6-1.html

Theoretically, other than different calling syntax, there's conceptually no difference between "out" parameters and returning values.

In practice, though, many languages (C, C++, Java, Python, ...) support "out" parameters accidentally by passing references to non-constant objects, and that's where things get ugly.