svn commit: r229794 - head/usr.bin/hexdump
Bruce Evans
brde at optusnet.com.au
Sun Jan 8 10:15:22 UTC 2012
On Sun, 8 Jan 2012, Bruce Evans wrote:
> ...
> Fixing these style bugs gives something like:
>
> %%%
> /*
> * Set end pointer. First make sure that p1 is not
> * the empty string..
> */
> p2 = *p1 == '\0' ? p1 + p1 + 1;
Grr, typo. One of the `+'s should be `:'. I hope I inverted the logic
of this expression correctly.
>
> /* Set conversion string. */
> cs[0] = *p1;
> cs[1] = '\0';
>
> %%%
> Possible furthe improvements:
> - some programmers can't would add unnecessary parentheses for the ?:
> operator. Even I might add them.
Since I changed `*p1' to `*p1 == `\0'' and inverted the logic, it has an
extra operator so it needs the parentheses more than before:
p2 = (*p1 == '\0' ? p1 : p1 + 1);
Not:
p2 = (*p1 == '\0') ? p1 : p1 + 1;
(since this adds parentheses where they are least needed), or
p2 = ((*p1 == '\0') ? p1 : p1 + 1);
(since this adds layers of parentheses which must be parsed to
see where they actually are).
Bruce
More information about the svn-src-head
mailing list