• 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: Optionals? A better option!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optionals? A better option!


  • Subject: Re: Optionals? A better option!
  • From: Kyle Sluder <email@hidden>
  • Date: Fri, 15 May 2015 12:06:38 -0500

On Fri, May 15, 2015, at 11:31 AM, Jens Alfke wrote:
> Yes, but when you evaluate (cdr nil) doesn’t the interpreter trigger an
> exception? (Sorry, it’s been decades since I used LISP.) Similarly, in
> Smalltalk-80 ‘null’ is a real object, a singleton of class
> UndefinedObject, but trying to message it is going to raise a
> message-not-handled exception. The difference from a nil pointer is
> mostly that you get a language-level rather than an OS-level exception.

Just as a point of esoterica, nothing about the C spec requires the null
pointer to map to a hardware-level trap. The only requirement is that
there exist a value called the null pointer in every pointer type, that
all null pointers compare equal to each other, and that they do not
compare equal to any non-null pointers.

It's not valid to dereference a null pointer, but what happens when you
do is undefined.

The assumption that dereferencing a null pointer would always lead to a
hardware fault led to a pretty serious vulnerability in the Linux
kernel: http://lwn.net/Articles/342330/

Here's some more elaboration:
https://software.intel.com/en-us/blogs/2015/04/20/null-pointer-dereferencing-causes-undefined-behavior

And all of this is why Swift and every other modern programming
languages goes the route of Optionals.

--Kyle Sluder

_______________________________________________

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: Optionals? A better option!
      • From: Scott Ribe <email@hidden>
References: 
 >Re: Optionals? A better option! (From: has <email@hidden>)
 >Re: Optionals? A better option! (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Optionals? A better option!
  • Next by Date: Re: Optionals? A better option!
  • Previous by thread: Re: Optionals? A better option!
  • Next by thread: Re: Optionals? A better option!
  • Index(es):
    • Date
    • Thread