Date: Sat, 20 Sep 1997 04:10:45 +1000 From: Bruce Evans <bde@zeta.org.au> To: bde@zeta.org.au, pst@shockwave.com Cc: cvs-all@FreeBSD.ORG, cvs-committers@FreeBSD.ORG, cvs-gnu@FreeBSD.ORG, jonny@coppe.ufrj.br, phk@FreeBSD.ORG Subject: Re: cvs commit: src/gnu/usr.bin/as/config atof-ieee.c src/gnu/usr.bin/ld/rtld rtld.c src/gnu/usr.bin/man/man man.c Message-ID: <199709191810.EAA25970@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>> void foo(bar) void *bar; { ... } >> ... >> foo(NULL); /* no prototype in scope */ >> >> `lint -p' should warn that the arg is inconsistent, but can't do so if >> NULL is ((void *)0). > >Could you please explain that more clearly? I see a perfectly good implied >prototype in scope, and the fact of the matter is that I should not be forced 1. There is no prototype in scope - the function is purposely declared old- style so that it does not provide a prototype. 2. The comment is supposed to make this clearer. >to typecast NULL into a particular pointer type, ever. Null is well defined >as a "pointer of some type, with a value of 0" To me, #define NULL (void *)0 >is the ultimate protection against the misuse of NULL. No, NULL is macro which expands to an implementation-defined null pointer constant. A null pointer constant is either an integral constant expression with value 0, or such an expression cast to `void *'. Portable programs must not assume a particular implementation. Even if NULL is a pointer (necessarily of type `void *'), it must be cast to the correct type in function calls. The cast is best done by putting a prototype in scope. Example: void foo(); ... foo((void *)0); /* no prototype in scope */ ... void foo(bar) int *bar; { ... } `lint -p' should warn that the arg is inconsistent, but the FreeBSD version doesn't. It warns for the equivalent `foo((char *)0)'. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709191810.EAA25970>