How does the compiler figure out conflicting return types, and why no warnings?
How does the compiler figure out conflicting return types, and why no warnings?
- Subject: How does the compiler figure out conflicting return types, and why no warnings?
- From: "Jonathan del Strother" <email@hidden>
- Date: Wed, 12 Dec 2007 12:43:17 +0000
Given this code :
#include <Cocoa/Cocoa.h>
@interface Disclosure : NSCell {
}
-(int)rotation;
@end
@implementation Disclosure
-(int)rotation {return 2;}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id disclosure = [[Disclosure alloc] init];
int rotation = [disclosure rotation];
NSLog(@"Rotation is %i", rotation);
[pool drain];
return 0;
}
I get no warnings no matter what warning switches I turn on, yet the
code fails miserably at runtime : the compiler is expecting
[disclosure rotation] to return a float (presumably from the -[NSEvent
rotation] message), so we get garbage data in the return value.
Obviously there's no way for the compiler to really know what to do
here, since 'disclosure' is of type id, and there's at least two
methods called 'rotation' with differing return types. But shouldn't
we at least get a warning?
And just how does the compiler decide which return type to use?
Jon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden