[cfe-dev] Objective-C return array type extension?
Eli Friedman
eli.friedman at gmail.com
Fri Jun 14 10:46:29 PDT 2013
On Fri, Jun 14, 2013 at 3:03 AM, Chen Xiliang <xlchen1291 at gmail.com> wrote:
> Hi all,
>
> I recently discovered that I can use a fixed size array as a return type
> in Objective-C like this:
>
> + (int[2])getIntArray {
> int i = 1;
> int i2 = 2;
> return (int[2]) {i, i2};
> }
>
> It woks as exactly as I expected in 32bits build (iOS device, iOS
> simulator, 32bits OSX app) but it failed badly in 64bits build.
>
> From the disassembly for 32bits build, I found that it is using
> _objc_msgSend_stret to send the message so the whole array is copied and
> returned.
> From the disassembly for 64bits build, it is using _objc_msgSend to send
> the message so only a pointer is returned.
>
> I wonder is this some undocumented extension or just undefined behavior
> that happened to be working?
>
Invalid code. clang is supposed to report an error.
-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130614/726e62e6/attachment.html>
More information about the cfe-dev
mailing list