Random nitpick...
Johan Adolfsson
Johan.Adolfsson at axis.com
Sun Sep 10 08:58:43 UTC 2006
----- Original Message -----
From: "Rich Felker" <dalias at aerifal.cx>
To: <busybox at busybox.net>
Sent: Sunday, September 10, 2006 3:42 AM
Subject: Re: Random nitpick...
> On Sat, Sep 09, 2006 at 07:17:15PM -0400, 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
> > 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?
>
> '\0' has type int, not type char. C is not C++. There is absolutely no
> reason to ever use '\0' or any other octal/hex single character
> constant except to obfuscate code in some misguided attempt (not even
> correct according to C language) to match types.
>
> Rich
Perhaps to the compiler, there's no reason.
I personally think that using '\0' makes it clear that we are adding
a null terminating char to a string and makes the code more readable -
and I prefer comparing pointers to NULL rather than 0 well.
/Johan
More information about the busybox
mailing list