[cfe-dev] How does clang objc select which selector to call for a given selector on ID?

David Chisnall David.Chisnall at cl.cam.ac.uk
Tue Dec 2 08:25:32 PST 2014


On 2 Dec 2014, at 16:03, Carlo Kok <carlokok at gmail.com> wrote:

> given an id x and NSStatusItem and NSString in scope (which both do length), one returns int, the other CGFloat, how does clang decide which one to pick? It seems to pick NSString, but I can't find the code that actually does this (or the rules that are used here)

It is undefined behaviour to do this.  Clang will pick one, but it is not consistently guaranteed to pick the same one (particularly across compiler versions).  With Apple's implementation of Objective-C, if it picks the wrong one then you will get a random value (and possibly stack corruption if the difference is between returning a scalar and a structure).  With the GNUstep implementation, you will get an error at run time (and possibly an NSInvalidArgumentException, depending on what you're linking).

David






More information about the cfe-dev mailing list