|
|
|
|
|
by e12e
1573 days ago
|
|
Thank you, but that's still not an answer to my question :) You pass in *out as an argument (allocated by caller, so caller has a handle on it), then the result/value of reverse ends up in *out - and then reverse returns *out as a return value in addition to having done its work. I was wondering why (I guess you could say I ask why it's a "function" not a "procedure"). I guess that the contract is that "reverse" takes ownership of *out as its passed in, and just happens to not return a pointer to a different buffer. But then my question is why it can't do its own allocation too... (which you did explain). In other words - why does reverse return a pointer rather than, say a success/error (or void - can it error? Maybe on arbitrary binary data?) |
|
I never changed the return value after I did this and didn’t see an issue at the time
For the record, this program was written casually on a live stream and is hardly a textbook definition of correctness :)