difference between NULL and nil?

I've searched but can't find a clear coherent answer. Could someone spell this out for me?

Thanks

macbook, Mac OS X (10.5.4)

Posted on Oct 1, 2008 5:05 PM

Reply
5 replies

Oct 1, 2008 5:14 PM in response to applehund

command-double-click is your friend


/* A null pointer constant. */
#if defined (STDDEFH) || defined (_needNULL)
#undef NULL /* in case <stdio.h> has defined it. */
#ifdef _GNUG_
#define NULL __null
#else /* G++ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else /* C++ */
#define NULL 0
#endif /* C++ */
#endif /* G++ */
#endif /* NULL not defined and <stddef.h> or need NULL. */
#undef _needNULL



#ifndef NULL
#define NULL _DARWINNULL
#endif /* ! NULL */
#ifndef nil
#define nil NULL
#endif /* ! nil */

Oct 1, 2008 5:49 PM in response to applehund

Apparently holding down the command key and double clicking on a variable brings up a window with a list of files where that variable is defined. (Something I did not know. Guess I learn something new every day! 🙂 .)

I assume you know how #define works.

Therefore if you have:

#define nil NULL

It means that the compiler is actually replacing every occurrence of nil with NULL.

So they are exactly the same.

Message was edited by: Nitzan Wilnai

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

difference between NULL and nil?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.