> Not really ok.  Given the way the ISO C standard is formulated, not
> casting NULL in this case is a genuine bug.
> 
> One can argue though, that defining NULL in such a way that it is not
> usable as a sentinel value would be really really silly, and that it
> is not our job to catch missing casts like this.  In that case though,
> I'd propose that we change our definition of NULL to
> 
> #define NULL ((void *)0)
> 
> instead of modifying our compilers.

After checking what Single Unix has to say (that NULL should be a void *
pointer of zero value), I suggest the following diff instead. Kernel
still needs NULL to be a scalar until all misuses of NULL instead of
zero (and vice versa) are fixed.

Index: sys/sys/param.h
===================================================================
RCS file: /cvs/src/sys/sys/param.h,v
retrieving revision 1.89
diff -u -p -r1.89 param.h
--- sys/sys/param.h     14 Jan 2011 00:04:16 -0000      1.89
+++ sys/sys/param.h     3 Apr 2011 22:10:38 -0000
@@ -48,7 +48,11 @@
 #ifdef         __GNUG__
 #define        NULL    __null
 #else
+#if defined(_KERNEL) || defined(_STANDALONE)
 #define        NULL    0L
+#else
+#define        NULL    ((void *)0)
+#endif
 #endif
 #endif
 
Index: include/dirent.h
===================================================================
RCS file: /cvs/src/include/dirent.h,v
retrieving revision 1.20
diff -u -p -r1.20 dirent.h
--- include/dirent.h    31 Dec 2010 19:54:05 -0000      1.20
+++ include/dirent.h    3 Apr 2011 22:10:38 -0000
@@ -85,7 +85,7 @@ typedef struct _dirdesc {
 #ifdef         __GNUG__
 #define        NULL    __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif /* __GNUG__ */
 #endif /* !NULL */
 
Index: include/locale.h
===================================================================
RCS file: /cvs/src/include/locale.h,v
retrieving revision 1.6
diff -u -p -r1.6 locale.h
--- include/locale.h    2 Jun 2003 19:34:12 -0000       1.6
+++ include/locale.h    3 Apr 2011 22:10:38 -0000
@@ -60,7 +60,7 @@ struct lconv {
 #ifdef         __GNUG__
 #define NULL   __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/stddef.h
===================================================================
RCS file: /cvs/src/include/stddef.h,v
retrieving revision 1.10
diff -u -p -r1.10 stddef.h
--- include/stddef.h    22 Sep 2009 21:40:02 -0000      1.10
+++ include/stddef.h    3 Apr 2011 22:10:38 -0000
@@ -68,7 +68,7 @@ typedef       __mbstate_t     mbstate_t;
 #ifdef         __GNUG__
 #define NULL   __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/stdio.h
===================================================================
RCS file: /cvs/src/include/stdio.h,v
retrieving revision 1.38
diff -u -p -r1.38 stdio.h
--- include/stdio.h     9 Nov 2009 00:18:27 -0000       1.38
+++ include/stdio.h     3 Apr 2011 22:10:38 -0000
@@ -59,7 +59,7 @@ typedef       __off_t off_t;
 #ifdef         __GNUG__
 #define        NULL    __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/stdlib.h
===================================================================
RCS file: /cvs/src/include/stdlib.h,v
retrieving revision 1.47
diff -u -p -r1.47 stdlib.h
--- include/stdlib.h    18 May 2010 22:24:55 -0000      1.47
+++ include/stdlib.h    3 Apr 2011 22:10:38 -0000
@@ -81,7 +81,7 @@ typedef struct {
 #ifdef         __GNUG__
 #define NULL   __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/string.h
===================================================================
RCS file: /cvs/src/include/string.h,v
retrieving revision 1.20
diff -u -p -r1.20 string.h
--- include/string.h    24 Sep 2010 13:33:00 -0000      1.20
+++ include/string.h    3 Apr 2011 22:10:38 -0000
@@ -47,7 +47,7 @@ typedef       __size_t        size_t;
 #ifdef         __GNUG__
 #define        NULL    __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/time.h
===================================================================
RCS file: /cvs/src/include/time.h,v
retrieving revision 1.18
diff -u -p -r1.18 time.h
--- include/time.h      6 Jan 2006 18:53:04 -0000       1.18
+++ include/time.h      3 Apr 2011 22:10:38 -0000
@@ -48,7 +48,7 @@
 #ifdef         __GNUG__
 #define        NULL    __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/unistd.h
===================================================================
RCS file: /cvs/src/include/unistd.h,v
retrieving revision 1.62
diff -u -p -r1.62 unistd.h
--- include/unistd.h    25 Jun 2008 14:58:54 -0000      1.62
+++ include/unistd.h    3 Apr 2011 22:10:38 -0000
@@ -59,7 +59,7 @@
 #ifdef         __GNUG__
 #define        NULL    __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif
 
Index: include/wchar.h
===================================================================
RCS file: /cvs/src/include/wchar.h,v
retrieving revision 1.11
diff -u -p -r1.11 wchar.h
--- include/wchar.h     24 Jul 2010 09:58:39 -0000      1.11
+++ include/wchar.h     3 Apr 2011 22:10:38 -0000
@@ -66,7 +66,7 @@
 #ifdef __GNUG__
 #define        NULL    __null
 #else
-#define        NULL    0L
+#define        NULL    ((void *)0)
 #endif
 #endif

Reply via email to