38 ms·
Right. Just think of the return value as an additional mutable formal parameter, and function return values as syntactic sugar for that additional parameter.
by Animats 9y ago
Right. Just think of the return value as an additional mutable formal parameter, and function return values as syntactic sugar for that additional parameter. The caller allocates space for the actual parameter.
- Animats 9y agoTo be more explicit y = f(g(h(x))); is really var hreturn; h(x, hreturn); var greturn; g(hreturn, greturn); // hreturn is no longer live var y; h(greturn, y); // greturn is no longer live Looked at this way, a function can return any fixed-size type without a copy. Some languages, mostly those in the Pascal/Modula family, did this explicitly. Instead of having a return statement, within a function, the name of the function was the return value, and code could assign to it, or pass it by reference to another function.