From owner-freebsd-standards@FreeBSD.ORG Sun Dec 7 20:31:07 2003 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AA0B816A4CE for ; Sun, 7 Dec 2003 20:31:07 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id C915343F75 for ; Sun, 7 Dec 2003 20:31:05 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id PAA07922; Mon, 8 Dec 2003 15:30:55 +1100 Date: Mon, 8 Dec 2003 15:30:54 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Marcel Moolenaar In-Reply-To: <20031201000659.GA48096@dhcp01.pn.xcllnt.net> Message-ID: <20031208150831.D4790@gamplex.bde.org> References: <20031201000659.GA48096@dhcp01.pn.xcllnt.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: standards@freebsd.org Subject: Re: 64-bit NULL: please review patch X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Dec 2003 04:31:07 -0000 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 and not centrally in . % 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 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 starting with ((__intptr_t)0) would be easier to change. Bruce