On 31 Jan 2011, at 09:59, Ivan Vučica wrote: > From what I saw, you commonly don't want to return structs in ObjC anyway. > Rather one should wrap stuff all into classes. Right?
See NSRange, NSPoint, NSSize, NSRect... NSRange is a particularly nasty corner case, because on any sane platform it's returned in registers (two integer registers), but on Linux it's returned on the stack (allocated in the caller, one integer register carries the pointer into the callee)[1]. This means that on FreeBSD, for example, GCC + the GNU runtime will return an NSRange with the location field set to 0 and the length field set to whatever the contents of the next register happened to be. On Linux, it will return whatever happened to be in the stack when the caller allocated the space. So, on Linux both fields have undefined values, but on (some) other platforms only the first one does. Since this depends on the calling convention used, it can vary both between operating systems and between architectures - if it works one way on Linux/x86, it may work a different way on FreeBSD/x86. If it works one way on FreeBSD/x86, it may work a different way on FreeBSD/SPARC. This is probably my least favourite corner case of Objective-C. David [1] Most braindead ABI decision ever: If you return a structure containing a single integer, Linux does it by allocating one word in the caller, passing a pointer to this in the integer register to the callee, storing the return value on the stack via this pointer, returning, then loading it from the stack. FreeBSD et al. do it by storing the value in the integer register and returning. And people wonder why I hate using Linux... -- Sent from my PDP-11 _______________________________________________ Discuss-gnustep mailing list [email protected] http://lists.gnu.org/mailman/listinfo/discuss-gnustep
