• 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:35:00 +0200

On Thursday, September 26, 2002, at 09:39 , Gerben Wierda wrote:

"is valid as long as the message returns an object; if it does, a message sent to nil will return nil. If the message sent to nil returns anything other than an object, the return value is undefined"

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).

It's a bad description, IMHO.

I was under the impression that any message sent to nil will just return nil and that's it. No harm done. But both statements above do suggest something else is going on. So: is it safe to send messages to nil? What does the runtime system exactly do with messages like that?

The fact is very very simple -- it does "return nil;" the same way as if the method was declared to return an id. Lowlevel it just means it zeroes $r3.

As for the "safe" part:

(i) you can *any time* *completely safely* send *any* message to nil, and it is guaranteed that nothing would crash and nothing happen;
(ii) if you want to use the returned value, the situation changes somewhat:
- in case the returned value is awaited in $r3 (in practice, if it is an integer or a pointer), it is safe to use it and presume it would be zero, nil, NULL;
- in case the returned value is awaited elsewhere (in practice, float returs and struct returns), it is not safe to use it anyhow (the result would be more or less random).
---
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.
References: 
 >nil messaging? Is it safe? (From: Gerben Wierda <email@hidden>)

  • Prev by Date: Re: Problem with 'scanf'
  • Next by Date: A little OT Help
  • Previous by thread: Re: nil messaging? Is it safe?
  • Next by thread: Re: nil messaging? Is it safe?
  • Index(es):
    • Date
    • Thread