Random nitpick...

Rob Landley rob at landley.net
Mon Sep 11 00:29:45 UTC 2006


On Sunday 10 September 2006 1:20 pm, Denis Vlasenko wrote:
> 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.

I could be convinced on NULL for pointer (I don't care much about that one), 
but not about the '\0' char thing.  Using an octal escape for that is just 
silly.  The nul terminator being 0 was portable even back in the days of 
minicomputers that didn't guarantee your char would be 8 bits.

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

You're arguing about type safety to a Python programmer.

> 	p[n] = NULL; /* reader: aha, p[n] is a pointer... */
> 	p[n] = '\0'; /* p is a string */

What type safety?  `\0` is an int.  printf("%d\n",sizeof('\0')); gives 4.

> 	p[n] = 0;    /* what is p[n]?! integer? or what? */

This was the approximate rationale behind hungarian notation, which was a very 
bad idea.

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

I can go either way on "NULL" for pointers, but replacing char=0 with 
char='\0'; is not a good cleanup.

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list