Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Dec 2003 15:30:54 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Marcel Moolenaar <marcel@xcllnt.net>
Cc:        standards@freebsd.org
Subject:   Re: 64-bit NULL: please review patch
Message-ID:  <20031208150831.D4790@gamplex.bde.org>
In-Reply-To: <20031201000659.GA48096@dhcp01.pn.xcllnt.net>
References:  <20031201000659.GA48096@dhcp01.pn.xcllnt.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 30 Nov 2003, Marcel Moolenaar wrote:

> Attached a patch to help us out in the various ways we may want
> or need to define NULL. First and foremost, it centralizes the
> definition so that we don't have to modify a dozen headers to
> make a change. Secondly, it defines NULL as 0L on ia64 when
> compiling for the LP64 runtime. When adding -milp32 to gcc (not
> yet supported), __LP64__ is not defined and NULL will be defined
> as 0. This is the correct behaviour.
>
> With the definition of NULL in a seperate header we can also
> utilize compiler built-in definitions for NULL is such exist or
> define NULL specially for lint or other conditions.
>
> Please review,

The separate header is too much.  Since the type of NULL is a type,
it should probably go in a _types.h file together with the declarations
of hundreds or thousands of other types.  Having a seperate header for
it is like having a seperate header for each type.  Since the type is
MD, it must be defined in each <machine/_types.h> and not centrally in
<sys/_types.h>.

% Index: include/dirent.h
% ===========================================================================
% --- include/dirent.h	2003/11/30 14:58:52	#4
% +++ include/dirent.h	2003/11/30 14:58:52
% ...
% @@ -81,10 +83,6 @@
%  #define DTF_REWIND	0x0004	/* rewind after reading union stack */
%  #define __DTF_READALL	0x0008	/* everything has been read */
%
% -#ifndef NULL
% -#define	NULL	0
% -#endif
% -
%  #else /* !__BSD_VISIBLE */
%
%  typedef	void *	DIR;

This should use '#define\tNULL\t__NULL'.  I dislike "#ifndef NULL" and plan
to remove it.  It mainly breaks warnings in applications that #define NULL.
Ifdefs are not needed to prevent redefinition to the system's common
value like they are for typedefs.

% Index: sys/sys/_null.h
% ===========================================================================
% *** /dev/null	Sun Nov 30 14:55:39 2003
% --- sys/sys/_null.h	Sun Nov 30 14:59:01 2003
% ***************
% *** 0 ****
% --- 1,37 ----
% + #ifndef NULL
% +
% + #ifdef __LP64__
% + #define	NULL	0L
% + #else
% + #define	NULL	0
% + #endif
% +
% + #endif

This central defininition depends on a gccism (__LP64__).

Hmm.  If we use _types.h then we already have a suitable MD integer
type, namely __intptr_t (intptr_t is optional in C99 but is required
in FreeBSD and maybe in POSIX in practice.  All the places that #define
NULL now could define it to ((__intptr_t)0) after including <sys/_types.h>
which they mostly already include.  Using a integral type would avoid
the problem that C++ doesn't permit ((void *)0) (unless it requires a
plain int type).

Howver, I'm not really happy with casting 0 on machines that don't
need it.  A centralized definition of __NULL in <sys/_types.h> starting
with ((__intptr_t)0) would be easier to change.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031208150831.D4790>