GNOME Bugzilla – Bug 54730
gmacros.h should include <stddef.h>
Last modified: 2004-12-22 21:47:04 UTC
There is comment in gmarcros.h saying: /* Provide definitions for some commonly used macros. * Some of them are only provided if they haven't already * been defined. It is assumed that if they are already * defined then the current definition is correct. */ To meet this purpose, it would be safer to include at least <stddef.h> here before defining NULL, TRUE, FALSE,... It would reduce the possibility to cause compile warnings or errors due to different definitions of these macros from what are expected by the compiler in use. Index: gmacros.h =================================================================== RCS file: /cvs/gnome/glib/gmacros.h,v retrieving revision 1.2 diff -u -r1.2 gmacros.h --- gmacros.h 2000/12/01 05:42:51 1.2 +++ gmacros.h 2001/05/15 23:32:54 @@ -102,6 +102,7 @@ # define G_END_DECLS #endif +#include <stddef.h> /* Provide definitions for some commonly used macros. * Some of them are only provided if they haven't already * been defined. It is assumed that if they are already
GLib never includes system headers, because we wouldn't be able to change what headers it includes without breaking application code. Also, system headers may introduce portability or other issues.
I'm seeing quite many compile warnings and a few errors when compiling glib/gtk+/pango source that use (void*)0 definition for NULL macro which is given in glib/gmacro.h. #ifndef NULL # ifdef __cplusplus # define NULL (0L) # else /* !__cplusplus */ # define NULL ((void*) 0) # endif /* !__cplusplus */ #endif This seems a common practice on gcc/c++ and maybe others, but Sun's native C compiler defines NULL as 0 (or 0L for 64bit-mode).
Let me reopen a bug as the issue was discussed on gtk-devel-list. The problem occurs when gmacro.h is included before stddef.h. Sun's Forte C compiler wants NULL be defined to 0, but including gmacro.h before stddef.h makes it be ((void*) 0), and this breaks glib and gtk+ build with the Forte in many places.
Sun Aug 5 08:25:30 2001 Owen Taylor <otaylor@redhat.com> * glib/gmacros.h: Include stddef.h so that we use the system's definition of NULL. (#54730) To the extent the contents of stddef.h differ between systems, this does introduce possible portability problems, but trying to guess the system definition of NULL seems to be very hard, and the system definition will be in stddef.h on any reasonable system. (In case of unreasonably systems, we can still back to the old way.) The discussion referred to is in the followups to: http://mail.gnome.org/archives/gtk-devel-list/2001-July/msg00118.html Apparently the problem here is that the Forte compiler allows casts from it's own NULL (0 or 0L) to function pointers, but does not allow casts from (void *)0 to function pointers.