• 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: nil messaging? Is it safe?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nil messaging? Is it safe?


  • Subject: Re: nil messaging? Is it safe?
  • From: Ondra Cada <email@hidden>
  • Date: Fri, 27 Sep 2002 01:42:20 +0200

On Thursday, September 26, 2002, at 10:57 , Nicholas Riley wrote:

On Thu, Sep 26, 2002 at 09:39:21PM +0200, Gerben Wierda wrote:
Now, I do not understand this. How can the compiler or the runtime
system know what the message will return? After all, nil has no class,
so there is no way of knowing the signature of the message (that is, the
return value).

The compiler keeps track of all available selectors (for all known
classes);

Right.

for a given selector there can be only one return type.

Wrong. In this case, compiler emits a warning, and uses a randomly(*) selected signature of those available for the selector.

(*) randomly from the programmer's POV; I bet the compiler does it very deterministically using the first one in its tables or so.

If
the selector is unknown, I think you can only get an object/nil return
type, but I'm not sure.

Then don't... well, I think it's vain anyway :(((

For an unknown selector, the compiler (emits a warning and) uses a signature whose return type (and all argument types, if any) is "id". That means such method can safely return anything which is losslessly convertable to/from id: in practice, any pointer or int (of the same size as pointer).

(Actually, so far as I know, smaller ints -- char and short -- work well too, with perhaps some quite sophisticated problems with DO. No guarantee here though.)
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: nil messaging? Is it safe?
      • From: Nicholas Riley <email@hidden>
References: 
 >Re: nil messaging? Is it safe? (From: Nicholas Riley <email@hidden>)

  • Prev by Date: Unusual error message
  • Next by Date: Re: Problem with 'scanf'
  • Previous by thread: Re: nil messaging? Is it safe?
  • Next by thread: Re: nil messaging? Is it safe?
  • Index(es):
    • Date
    • Thread