From owner-freebsd-hackers Fri Feb 14 18:18:42 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id SAA20748 for hackers-outgoing; Fri, 14 Feb 1997 18:18:42 -0800 (PST) Received: from nic.follonett.no (nic.follonett.no [194.198.43.10]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA20743 for ; Fri, 14 Feb 1997 18:18:38 -0800 (PST) Received: (from uucp@localhost) by nic.follonett.no (8.8.5/8.8.3) with UUCP id DAA19069 for hackers@FreeBSD.ORG; Sat, 15 Feb 1997 03:17:15 +0100 (MET) Received: from oo7 (oo7.dimaga.com [192.0.0.65]) by dimaga.com (8.7.5/8.7.2) with SMTP id CAA20267 for ; Sat, 15 Feb 1997 02:55:06 +0100 (MET) Message-Id: <3.0.32.19970215025505.00c3f100@dimaga.com> X-Sender: eivind@dimaga.com X-Mailer: Windows Eudora Pro Version 3.0 (32) Date: Sat, 15 Feb 1997 02:55:07 +0100 To: hackers@FreeBSD.ORG (Joerg Wunsch) From: Eivind Eklund Subject: Re: NULL as ((void*)0) (was Re: strlen() question) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk At 12:26 AM 2/15/97 +0100, J Wunsch wrote: >As Eivind Eklund wrote: > >> I hereby propose changing the default declaration of NULL under FreeBSD from >> #define NULL 0 >> to >> #define NULL ((void*)0) >> for better type-safety and ease of transition to other architechtures >> (e.g. Alpha). This will probably save us from a quite a few varargs-voes, >> as well as generally making sure the code-base is using NULL correctly, >> which is important for those reading source-code. > >Nope, it wouldn't get you anywhere. The vararg-woes cannot be solved >by it either, since you gotta cast to the exact type in any case >anyway. Passing (void *)0 into a vararg list is as invalid as passing >0 there if the target type is e.g. char *. It isn't invalid except at the virtual machine level - it invoke undefined behaviour. In many cases (e.g. FreeBSD today) even passing an uncasted 0 works. In all cases, a void* passed instead of a char* will work (I can dig up chapter and verse for this one - bad example :) Passing void* for eg int* involve undefined behaviour, though. But on 99% of todays available hardware (excluding eg Prime and older Crays) pointers to different typed objects have the same size and the same internal structure. For this case, it will work. And in no case will it work worse[1]. >It wouldn't ensure the code base is using NULL everywhere either, This wasn't what I was thinking of - quite the opposite. I was thinking of making sure the code base wasn't abusing NULL in a non-pointer context, and make programming environment somewhat more precise for beginners. >See also the comp.lang.c FAQ. I have done, repeatedly and at regular intervals. comp.std.c is also to be recommended for those wanting a nitpicker or compiler-writer view of C. >The only reason to use NULL is to make it more obvious to the reader >that you're thinking of a pointer context. Agreed. [1] There has come up one serious objection here, relating to C++. If this objection is correct, it mean that the proposal absolutely should be dropped. Besides, nobody but me seems to be in favour, and it isn't important to me, so... Eivind Eklund perhaps@yes.no http://maybe.yes.no/perhaps/ eivind@freebsd.org