> Returning multiple values is something that would require ABI support.
Uh, so what?
> Only values in the registers can be returned because the callee stack frame vanishes at return. Returning structs is already something poorly supported, because if it doesn't fit in registers, where do you store it then?
On the stack of course. Also, returning structs isn't "poortly supported" at all, it works just fine.
> The reason C++ can do it is because new/delete are part of the language,
That's simply nonsense.
Posted Jul 1, 2012 22:24 UTC (Sun) by nix (subscriber, #2304)
[Link]
To be fair, returning structures was poorly supported once. Of course that was in about 1980, but it explains some properties of the standard C and POSIX library (e.g. why stat() does not return a 'struct stat').
Why learn C? (O'Reilly Radar)
Posted Jul 1, 2012 22:38 UTC (Sun) by juliank (subscriber, #45896)
[Link]
I'd say another reason is that it's much easier to check for errors if your function returns some integer and passes the real result via a pointer.
Why learn C? (O'Reilly Radar)
Posted Jul 2, 2012 9:29 UTC (Mon) by nix (subscriber, #2304)
[Link]
Well, if there's only one error, it's easier to use the function if you just return the pointer or NULL.
Structures and results
Posted Jul 12, 2012 16:44 UTC (Thu) by alex (subscriber, #1355)
[Link]
Or to emulate old-school styles return NULL and set the global errno ;-)
Why learn C? (O'Reilly Radar)
Posted Jul 12, 2012 20:04 UTC (Thu) by hummassa (subscriber, #307)
[Link]
HRESULT feelings.
Why learn C? (O'Reilly Radar)
Posted Jul 12, 2012 20:08 UTC (Thu) by hummassa (subscriber, #307)
[Link]
> On the stack of course.
Actually, IIRC, if the struct/class instance fits in one or two registers, those are used to return it; if it does not fit, the caller reserves the space just below the return address/stack frame on the stack (so the callee knows where to put it).