Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 15, 2008, 09:24 AM   #1
Darkroom
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
The Difference Between NIL and NULL...

... is what exactly?
Darkroom is offline   0 Reply With Quote
Old Jul 15, 2008, 09:36 AM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Style.

They will both be compiled to 0.

From what I can tell the stylistic difference is that NULL is used to indicate a null pointer to a primitive type, and nil is used to indicate a null pointer to an Object.

-Lee
lee1210 is offline   0 Reply With Quote
Old Jul 15, 2008, 09:37 AM   #3
TimJim
macrumors 6502a
 
Join Date: May 2007
NIL is no value/zero. We're winning 5-nil
NULL is the absence of data (when writing software)
TimJim is offline   0 Reply With Quote
Old Jul 15, 2008, 11:10 AM   #4
iSee
macrumors 68040
 
iSee's Avatar
 
Join Date: Oct 2004
Assuming we're talking about Objetive-C:
nil (all lower-case) is a null pointer to an Objective-C object.
Nil (capitalized) is a null pointer to an Objective-C class.
NULL (all caps) is a null pointer to anything else.

So, conceptually, they mean the same thing but for different categories of things. They all have the same representation, too; they all happen to have the numeric value of 0.

I don't know whether or not NIL (all upper-case) has special meaning in Objective-C.
iSee is offline   0 Reply With Quote
Old Jul 15, 2008, 05:47 PM   #5
NSNick
macrumors regular
 
Join Date: Jun 2008
Location: Washington D.C.
Darkroom, I believe on your avatar, the letter immediately following NS should be capitalized.
NSNick is offline   0 Reply With Quote
Old Jul 15, 2008, 06:17 PM   #6
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
Quote:
Originally Posted by NSNick View Post
Darkroom, I believe on your avatar, the letter immediately following NS should be capitalized.
but then it would be an ex-object... and NSSexObject doesn't play with the term/concept as much... anyway...

Quote:
Originally Posted by iSee View Post
Assuming we're talking about Objetive-C:
nil (all lower-case) is a null pointer to an Objective-C object.
Nil (capitalized) is a null pointer to an Objective-C class.
NULL (all caps) is a null pointer to anything else.

So, conceptually, they mean the same thing but for different categories of things. They all have the same representation, too; they all happen to have the numeric value of 0.

I don't know whether or not NIL (all upper-case) has special meaning in Objective-C.
so to get this straight...??

Code:
[NSApp beginSheet:sheet
   modalForWindow:mainWindow
      modalDelegate:nil                 //pointing to an object (modelDelegate?) and making it zero?
      didEndSelector:NULL             //pointing to a non object/class and making it zero?
           contextInfo:NULL];           //pointing to a non object/class and making it zero?
Darkroom is offline   0 Reply With Quote
Old Jul 15, 2008, 06:27 PM   #7
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
That looks correct.
Catfish_Man is offline   0 Reply With Quote
Old Jul 15, 2008, 08:30 PM   #8
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Don't forget NSNull!
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Aug 30, 2008, 07:38 PM   #9
stimpy77
macrumors newbie
 
Join Date: Aug 2008
Quote:
Originally Posted by HiRez View Post
Don't forget NSNull!
Please share.

EDIT: Nevermind.

http://developer.apple.com/documenta...cles/Null.html

NSNull is a singleton object used to represent a null value where nil is prohibited, namely collections. I come from the Windows world, this kinda reminds me of System.DBNull in C# ...
stimpy77 is offline   0 Reply With Quote
Old Aug 30, 2008, 08:41 PM   #10
Littleodie914
macrumors 68000
 
Littleodie914's Avatar
 
Join Date: Jun 2004
Location: Rochester, NY
Yea, the different types can get confusing at times. In all my experience, I've only used the "nil" and "NULL" keywords, referring to an objective-c object pointer, and a primitive type pointer, respectively. I've never needed anything else, but maybe I just haven't gotten deep enough.
Littleodie914 is offline   0 Reply With Quote
Old Aug 31, 2008, 07:19 PM   #11
certsoft
macrumors member
 
Join Date: Sep 2007
NIL is a reserved word in Pascal, I don't know what it would be doing in C (although I've never used objective C). Like NULL, it's value is usually zero.
certsoft is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Nil value in variable when it should be non-nil moonman239 iPhone/iPad Programming 17 Apr 21, 2014 05:13 PM
UICollectionViewCell variable is nil moonman239 iPhone/iPad Programming 2 Feb 22, 2014 08:37 PM
Retrieved CGPath shows as nil.. RottenApple2 iPhone/iPad Programming 6 Sep 22, 2012 09:58 AM
Error Message: endSheet: requires a non-nil sheet rien333 Mac Programming 2 Sep 2, 2012 01:46 PM
Why would I get nil for [self.tableView cellForRowAtIndexPath:indexPath]? Ron C iPhone/iPad Programming 20 Jun 8, 2012 06:56 PM

Forum Jump

All times are GMT -5. The time now is 12:09 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC