Random nitpick...

Denis Vlasenko vda.linux at googlemail.com
Sun Sep 10 17:20:55 UTC 2006


On Sunday 10 September 2006 01:17, Rob Landley wrote:
> -               oneline[sizeof(oneline) - 1] = 0;
> +               oneline[sizeof(oneline) - 1] = '\0';
> 
> Actually, I prefer = 0, since that's what we're doing.  Going out of your way 
> to escape the 0 and put it in quotes is kind of silly.
> 
> I also tend not to use NULL for the same reason (0 is 0), although I find NULL 
> slightly less silly than the above.  (And yes the compiler treats 0 

Linus convinced me otherwise. I don't have his mail at hand,
but basically he says that he regards NULL as null _pointer_,
and in kernel NULL is #defined to ((void*)0), not 0.

It all boils down for type safety (when you have that special
#define) and easier-to-read code:

	p[n] = NULL; /* reader: aha, p[n] is a pointer... */
	p[n] = '\0'; /* p is a string */
	p[n] = 0;    /* what is p[n]?! integer? or what? */

But I am not religious about it and will follow your rules,
not Linus' ones.

> specially, you can assign it to anything, without a typecast.  However, since 
> we _do_ assign constants into characters, and even do math on them 
> (val=x-'0';), what exactly is wrong with using a constant zero?
--
vda



More information about the busybox mailing list