Well that would be wrong. Quoting my 25 year old copy of K&R:

C guarantees that no pointer that validly points to data will contain zero, so a return value of zero can be used to signal an abnormal event..... We write NULL instead of zero, however, to indicate more clearly that this is a special value for a pointer.

In those days it used to be defined:

#define NULL 0

now it is normally defined

#define NULL ((void *) 0)

In the original K&R C there was no void type, so they could not use this definition back then. This makes things like

   if (!malloc(42))

valid portable C, although I feel

   if (malloc(42) == NULL)

has greater clarity. The first style got into favour years ago, when compilers were more basic and often produced tighter code for that form. I don't know why people continue with it, unless they are entering an obfuscated C contest.

Regards,
Steve


Augmentics. wrote:

Personally I like to #define NULL to be the string "fish".
Works most of the time, except when it doesn't.

Perhaps I should have used Unicode?

Note: with French C compilers one has, of course, to use "poisson".


Reply via email to