On Sun, Dec 13, 2009 at 10:29:36PM +0100, Carsten Breuer wrote:

> > You could also argue that the do_something definition is buggy,
> > since it's not one statement.
> 
> Correct. But if you use brackets the code do what you want and
> you get the result what you expect.

Sure, but if you use brackets in the macro, the code does what you
want as well. :)  The main downside for me of mandating brackets in
the caller is that it wastes vertical space, which tends to be
scarce.  But yes, you'll have to trust whomever defined the macro to
not have done something stupid, which you can't always rely on.


> Lint complains about both.

I'm not sure if Lint is a good standard. :)


> > E.g. the Linux kernel takes this stance, and wraps such macros in do
> > { } while (0) blocks:
> > #define local_irq_enable() \ do { trace_hardirqs_on();
> > raw_local_irq_enable(); } while (0) #define local_irq_disable() \ do
> > { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
> 
> One possible way, but a bit tricky.
> In most code you have the time to use inline functions (C99)
> instead of makros. We use them a lot and try too avoid
> any preprocessor macros at all.

In cases where they can be used (i.e. the macro doesn't modify any
of its arguments), I definitely prefer inline functions as well.
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to