<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jul 26, 2008, at 12:02 AM, Chris Hanson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">On Jul 25, 2008, at 6:28 PM, Ted Kremenek wrote:<br><br><blockquote type="cite"><blockquote type="cite">It is, in fact, an error to return a NSMutableArray in a method<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">that's prototyped to return an NSArray due to C pointer aliasing<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">rules. The 'id' type is the closest thing that Objective-C has to a<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">'generic object pointer type', so if a method wants to return a<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">pointer to an object of more than one type, it really should declare<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">the return type as 'id'. Again, this is due to the C pointer<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">aliasing rules rather than any OO conceptual rules.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Again, I'm not certain how much C99's aliasing rules apply to<br></blockquote><blockquote type="cite">Objective-C object references. Objective-C doesn't have a formal<br></blockquote><blockquote type="cite">specification akin to C99, so the specification (if you want to call<br></blockquote><blockquote type="cite">it that) is whatever the current compiler implementation allows.<br></blockquote><br>The current specification of Objective-C is "The Objective-C 2.0 Programming Language" at <<a href="http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/">http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/</a>>.<br></span></blockquote><div><br></div><div>Thanks Chris! What I meant by a "formal" specification is something with the detail to write a compiler and runtime with. The document you reference (while excellent) doesn't provide that kind of detail. In our implementation of Objective-C support in Clang, we are really leaning on the knowledge of specific people who either had an hand in conceiving the language or implemented its support in gcc.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">John is also incorrect about the above: It is *not* an error, in Objective-C, to return an instance of a subclass from a method prototyped as returning an instance of the superclass.</span></blockquote><div><br></div><div>I don't think I addressed that point directly, and I'm glad you did so. This idea follows from standard type theory for functions: the return type is allowed to be a covariant type.</div><div><br></div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">Objective-C is its own language that extends C99, not a preprocessor for C99, and this is one of the extensions that Objective-C adds. </span></blockquote><div><br></div><div>Exactly.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "> In fact, in Objective-C it is not possible to say "this method returns an instance of specifically this class and no other class" -- you can only say "this method returns an instance of this class or any subclass."</span></blockquote></div><div><br></div>Excellent point. I don't think most standard OO languages allow you to express the first statement either. (others please chime in on this one if you know better!)</body></html>