Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!inria!ircam!erik!eckel From: eckel@erik.ircam.fr (Gerhard Eckel) Newsgroups: comp.sys.next Subject: what Obj-C methods return Keywords: Objective-C Message-ID: <1062@ircam.ircam.fr> Date: 3 May 90 17:20:43 GMT Sender: news@ircam.ircam.fr Reply-To: eckel@ircam.UUCP (Gerhard Eckel) Distribution: comp.sys.next Organization: l'Institut de Recherche et Coordination Acoustique-Musique Lines: 41 I try to write a 'send' function for a SMALL lisp interpreter that sends messages to Obj-C objects and receives the return values from the corresponding methods (this is similar to the 'send' function of the objc package in Common Lisp on the NeXT). I try to use objc_msgSend() which returns an id. I did some assembler hacking to get the other 4 bytes (asm("movel d1, something")). I found that Obj-C doesn't return structures correctly that are bigger than 8 bytes. C functions return such structures over the stack (it seems that the compiler uses the register a1 to pass the address - data smaller than 8 bytes is returned in the registers d0 and d1 as far as I could see). It seems that it is a bug since the methods try to copy the data using register a1. But where does it end up (I hate 'Bus error' and 'Segmentation fault')? Consider the following fragment: typedef struct { int a, b, c; } threeInts; @interface SomeClass : SomeSuperClass { threeInts someInts; } - (threeInts) someMethod; @end @implementation SomeClass - (threeInts) someMethod { return someInts; } @end id instance = [SomeClass new]; // the following line doesn't work // (i.e. the data is not copied into r) threeInts result = [instance someMethod]; // it works for twoInts (struct { int a, b; }) Any idea? Is this how it should be? Anything in the doc that I missed? Anybody else who tried to do a similar thing? Gerhard Eckel IRCAM, Paris eckel@ircam.fr