• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How does the compiler figure out conflicting return types, and why no warnings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How does the compiler figure out conflicting return types, and why no warnings?
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: type checking on enums
  • Next by Date: Re: pragma nowarn
  • Previous by thread: Re: type checking on enums
  • Next by thread: Re: How does the compiler figure out conflicting return types, and why no warnings?
  • Index(es):
    • Date
    • Thread