DragonFly submit List (threaded) for 2005-01
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
Re: Cleanup Base: fetch
:> Matthew Dillon wrote:
:> > :Isn't it better to use the '\0' to make it clear it's a character?
:> > :style(9) says this:
:> > :
:> > : Do not use ! for tests unless it is a boolean, e.g. use
:> > :
:> > : if (*p == '\0')
:> > :
:> > : not
:> > :
:> > : if (!*p)
:> > :
:> > :Of course it ends up being personal preference, but anyway, just curious.
:> >
:> > Something like '\n' at least has some readability value, but
:> > '\0' doesn't, really. Or at least, not much.
:> >
:> > I guess it's personal preference, I could go either way but I
:> > would tend to just use 0.
:>
:> Would 0 not be 32-bit and '\0' 8-bit?
:
:GCC knows the difference. The above code will produce assembler like:
:
: cmpb $0,(%eax) //compare byte to the address pointed to by eax
: //some jump condition
:
:If you ever have any doubts, try "%gcc -S the_name_of_your_program.c".
:This command will produce a filed called "the_name_of_your_program.s",
:which is AT&T syntax assembler. See the man for gcc and info as.
:
:-Zera Holladay
More precisely, all modern compilers can internally cast simple
constants to contrained sizes when the operation would otherwise
return the exact same result as what the C spec says should happen.
So, in this case, the C equivalent of (int)charary[n] == (int)0
is the same as (char)charary[n] == (char)0. So the same code
is produced whether 0 or '\0' is used, even when -O is not
specified.
-Matt
Matthew Dillon
<dillon@xxxxxxxxxxxxx>
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]