[PATCH RESEND] size reduction and coding style for who.c

Rob Landley rob at landley.net
Sun Mar 12 18:35:48 UTC 2006


On Sunday 12 March 2006 5:33 am, Yann E. MORIN wrote:
> Hello all!
>
> On Saturday 11 March 2006 192, Rob Landley wrote:
> > Changing spaces to tabs is cool.  Why the extra curly brackets around
> > single line ifs?  (I haven't rejected this one, I'm just asking if
> > there's a rationale here.  Seems an aesthetic choice.)
>
> Because the statement in the if might be a macro, and thus you wouldn't get
> the expected behavior.

In which case we want to catch the defective macro as soon as possible, rather 
than hide it by defensively coding everywhere to guard against the symptoms 
rather than detect the problem.

The Linux kernel codingstyle document says:

> Macros with multiple statements should be enclosed in a do - while block:
>
> #define macrofun(a, b, c)                       \
>        do {                                    \
>                if (a == 5)                     \
>                        do_this(b, c);          \
>        } while (0)

For exactly this reason.  I believe we've discussed this before here too, 
although it's been a while.

The "do { blah } while(0)" construct in a macro behaves as a single statement 
when attaching to if() or for() constructs.

> To which 'if' does the 'else' refer to, when the macro has been expanded by
> the preprocessor?

Known problem, with known solution.

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list