coding style for who.c
Allan Clark
allanc at chickenandporn.com
Mon Mar 13 19:19:47 UTC 2006
On 3/14/06, Rob Landley <rob at landley.net> wrote:
>
> On Monday 13 March 2006 1:54 pm, Robin Farine wrote:
> > On Sunday March 12 2006 06:24, Rob Landley wrote:
> > > If one of them is a constant, it emits no warning.
> >
> > Indeed. I could not reproduce any gcc warning with 'if (a & b)', 'a'
> > and 'b' being constants or variables. Must be due to a mistake
> > while picking mushrooms.
>
> It might have produced a warning on older versions.
>
> if (a & b) doesn't work quite like if (a && b), but it's not the obvious
> error
> that if (a = b) tends to be. If you restrict yourself to logic values
> rather
> than arbitrary numbers, and don't mind losing the short circuit behavior,
> then something if (a==b & c==d) will in fact work as expected.
(Rob gets two copies, reply/reply-all typo that compilers don't catch)
In large projects that actually use code-inspection, and hunt/kill
warnings, double-parenthesis
if (( a = b )) ...
... and LHS constants:
if (NULL == (fd = open (... )) )
... tend to show "yeah, I meant that when I wrote that, it's not a coding
typo" even if they don't add obvious readability. In addition
(double-parens) to quieting the warning, or (NULL == x) using the compiler
to avoid (a = 0) errors, this coding style lets us skim quickly to things we
need to question.
..so it's not a bad habit, BB or otherwise :)
Allan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/busybox/attachments/20060314/ee36fdfa/attachment.htm
More information about the busybox
mailing list