coding style for who.c

Paul Fox pgf at brightstareng.com
Sun Mar 12 04:27:53 UTC 2006


 > On Saturday 11 March 2006 2:26 pm, Robin Farine wrote:
 > > On Saturday March 11 2006 19:50, Devin Bayer wrote:
 > > > In addition, I dislike having to make
 > > > 	if(a = strchr(str,'-'));
 > > > into
 > > > 	if((a = strchr(str,'-')));
 > > >
 > > > How can the second one be considered easier to read? To fix this
 > > > you need to add -Wno-parentheses to the CPPFLAGS.

please don't do that -- it just hides a common coding bug.  but i
agree that the second style above isn't clearer.  to avoid the warning
and keep it readable, i'd suggest the following, which breaks up
the parentheses and makes it more obvious what's going on.
  	if ((a = strchr(str,'-')) != 0 );

in this _particular, case, however, the entire statement would
be better written as:
  	a = strchr(str,'-');
;-)

 > >
 > > It is more to make explicit that you want an '=' instead of an '=='
 > > here than to improve readability, likewise for &, |, ... vs &&,
 > 
 > For & the C precedence rules are actually wrong, it should bind _tighter_ than 
 > == and friends, but doesn't because way back in the day there was no && and & 
 > was used for decision making.  Meaning x==2 & y had to be (x==2) & y, not
 > x == (2 & y), because & had to fill in for &&.
 > 
 > By the time && was introduced, retroactively changing the precedence of & 
 > would have broken too much existing code.  So there you can't get away from 
 > the parentheses...

do you have a citation for this?  i've never before heard that &
preceded &&, implementation-wise.  all i remember was a quote
from either "K" or "R" saying that they thought that this
precedence botch was one of their great regrets.  or somesuch.

paul
=---------------------
 paul fox, pgf at brightstareng.com



More information about the busybox mailing list