• 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
Re: why doesn't the compiler complain?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why doesn't the compiler complain?


  • Subject: Re: why doesn't the compiler complain?
  • From: Matt Neuburg <email@hidden>
  • Date: Mon, 26 Apr 2010 15:45:15 -0700
  • Thread-topic: why doesn't the compiler complain?

On or about 4/26/10 1:22 PM, thus spake "Greg Parker" <email@hidden>:

> On Apr 26, 2010, at 1:01 PM, Matt Neuburg wrote:
>> Here's my test:
>> MyClass:
>> - (void) tryme: (NSString*) s;
>> MyClass2:
>> - (void) tryme: (NSArray*) s;
>>    MyClass* thing = [[MyClass alloc] init];
>>    NSString* s = @"Howdy";
>>    [(id)thing tryme: s];
>>
> In this test, the mismatch is an NSString* parameter vs an NSArray* parameter.
> That mismatch is "safe": the compiled code for the call site looks the same
> either way. The compiler does not warn about this by default.

Thanks for this extensive reply; it taught me a lot.

Here's something interesting. If I reverse the declaration order of MyClass
and MyClass2, like this:

>> MyClass2:
>> - (void) tryme: (NSArray*) s;
>> MyClass:
>> - (void) tryme: (NSString*) s;
>>    MyClass* thing = [[MyClass alloc] init];
>>    NSString* s = @"Howdy";
>>    [(id)thing tryme: s];

...Now the compiler *does* complain about that last line - it ways I'm
passing a string when an array was expected.

So I guess the compiler treats the *first* declaration of a method
name-and-signature that it encounters as the "real" one.

Now, that's okay, I guess (especially since there's a warning I can turn on
to detect even this level of conflict - thanks for explaining about that),
as long as the compiler is correctly foreshadowing the behavior of the
runtime. I take it from what you say about the compiled code being the same
that it is... m.

--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: why doesn't the compiler complain?
      • From: "Paul Sanders" <email@hidden>
References: 
 >Re: why doesn't the compiler complain? (From: Greg Parker <email@hidden>)

  • Prev by Date: Re: NSManagedObject, retain count and dealloc:
  • Next by Date: Re: conflict between Core Graphics and NSView graphics
  • Previous by thread: Re: why doesn't the compiler complain?
  • Next by thread: Re: why doesn't the compiler complain?
  • Index(es):
    • Date
    • Thread