Date: Mon, 01 Mar 2004 14:39:06 -0800 From: Tim Kientzle <tim@kientzle.com> To: Erik Trulsson <ertr1013@student.uu.se> Cc: current@freebsd.org Subject: Re: NULL vs 0 vs 0L bikeshed time Message-ID: <4043BB8A.3010601@kientzle.com> In-Reply-To: <20040301173231.GA61430@falcon.midgard.homeip.net> References: <xzpoergtt6z.fsf@dwp.des.no> <200403011707.i21H7bY96897@lakes.dignus.com> <20040301173231.GA61430@falcon.midgard.homeip.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Erik Trulsson wrote: > On Mon, Mar 01, 2004 at 12:07:37PM -0500, Thomas David Rivers wrote: >>>Mark Murray <mark@grondar.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4043BB8A.3010601>