From owner-freebsd-current@FreeBSD.ORG Mon Mar 1 14:39:54 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0F9B216A4CE for ; Mon, 1 Mar 2004 14:39:54 -0800 (PST) Received: from kientzle.com (h-66-166-149-50.SNVACAID.covad.net [66.166.149.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id B0D9B43D48 for ; Mon, 1 Mar 2004 14:39:53 -0800 (PST) (envelope-from tim@kientzle.com) Received: from kientzle.com (p54.kientzle.com [66.166.149.54]) by kientzle.com (8.12.9/8.12.9) with ESMTP id i21Md690012878; Mon, 1 Mar 2004 14:39:08 -0800 (PST) (envelope-from tim@kientzle.com) Message-ID: <4043BB8A.3010601@kientzle.com> Date: Mon, 01 Mar 2004 14:39:06 -0800 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.4) Gecko/20031006 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Erik Trulsson References: <200403011707.i21H7bY96897@lakes.dignus.com> <20040301173231.GA61430@falcon.midgard.homeip.net> In-Reply-To: <20040301173231.GA61430@falcon.midgard.homeip.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: des@des.no cc: mark@grondar.org cc: current@freebsd.org Subject: Re: NULL vs 0 vs 0L bikeshed time X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: kientzle@acm.org List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Mar 2004 22:39:54 -0000 Erik Trulsson wrote: > On Mon, Mar 01, 2004 at 12:07:37PM -0500, Thomas David Rivers wrote: >>>Mark Murray writes: >>> >>>>I'd like to commit the following patch. It makes sure that for C >>>>and the kernel, NULL is a ((void *)0) >>> >>>This is not correct, because it makes NULL unusable for function >>>pointers; you can assign 0 to a function pointer, but not (void *)0. >> >> That assignment seems to work... I thought (void *) was assignable to >> any function pointer... (Isn't (void *) assignable to any pointer?) > > To any _object_ pointer, not to a function pointer. Null pointers are > special however. I was curious about this, so I looked it up. ANSI/ISO 9899-1990, Section 6.2.2.3: "An integral constant expression with the value 0, or such an expression cast to type void * is called a null pointer constant. If a null pointer constant is assigned to ... a pointer, the constant is converted to a pointer of that type. Such a pointer ... is gauranteed to compare unequal to a pointer to any object or function." There's some earlier text about void* assignments that seems to restrict assigning void* to function pointers. The conclusion I draw from this: int (*f)(void); void *p; f = p; /* NOT LEGAL: Can't assign void* to function ptr */ f = (void *)0; /* LEGAL: Can assign NULL to function ptr */ f = 0; /* LEGAL: Can assign NULL to function ptr */ Tim Kientzle