After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 54730 - gmacros.h should include <stddef.h>
gmacros.h should include <stddef.h>
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
1.3.x
Other Solaris
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2001-05-15 23:37 UTC by Hidetoshi Tajima
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Hidetoshi Tajima 2001-05-15 23:37:22 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
Comment 1 Havoc Pennington 2001-06-04 22:10:44 UTC
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.
Comment 2 Hidetoshi Tajima 2001-06-04 23:03:10 UTC
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).


Comment 3 Hidetoshi Tajima 2001-07-25 19:15:35 UTC
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.

Comment 4 Owen Taylor 2001-08-05 12:37:41 UTC
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.