Subject: Re: a few minor cleanups to src/share/misc/style
To: None <tech-kern@netbsd.org, tech-userlevel@netbsd.org>
From: Matthias Buelow <mkb@mukappabeta.de>
List: tech-kern
Date: 03/23/2001 01:25:27
"Greg A. Woods" <woods@weird.com> writes:
> * Don't use `!' for tests unless it's a boolean.
A reasonable recommendation, imho...
> * E.g. use "if (*p == '\0')", not "if (!*p)".
>
>The test *is* boolean, damnit! :-)
look at it like this for once:
basically, the first expression says:
if dereferenced-pointer-value of p is the nul character, then ...
whereas the second expression says:
if not dereferenced-pointer-value of p is not integer zero, then ...
maybe you might understand why some people prefer the first expression,
even though the second is "faster to type".
mkb
(I personally prefer the order "'\0'==*p", for hopefully obvious reasons)