Name: (frozen_t)(void*) 2010-08-29 17:00
int a = NULL + 5;
printf("%d\n", a);Prints 5, therefore NULL is #defineD to 0.
int a = NULL + 5;
printf("%d\n", a);if (ptr == 0) because the integer literal "0", according to the C spec, will always be converted to NULL (when cast to a pointer type), no matter what the actual representation of NULL is. (And the "==" operator will perform that implicit cast.) Using 0 instead of NULL is slightly more portable, for those people who insist upon targeting the moronic broken platforms where NULL (the macro) doesn't work quite right or doesn't appear in the right header.(void *)0 is NULL for pointers to data, but broken for pointers to functions.
test.c:4:6: warning: incompatible pointer to integer conversion initializing
'void *', expected 'int' [-pedantic]
int a = NULL + 5;
^ ~~~~~~~~
...==0!....
NULL is a mistake but I personally appreciate it because I understand that it's not the thing at fault. The problem of "an object does not exist here" is daunting to get around. It's no different from saying any object that does not exist when requested is equatable to numeric 0 or the array escape character /0 - we'd just have to deal with ZeroPointerExceptions and other such language-specific nonsense....==compile-time-constant is always better written as compile-time-constant == ...
if (x = 5)
if (5 = x)