On Wed, Jun 19, 2002 at 01:38:52PM -0700, Paul Jackson wrote:
> Yes - leave them out (speaking out of context here - hopefully still
> useful).
>
> Remove the warnings instead.
>
> I've gotten in the habit of having the following form to
> optional code logic:
>
> In some header file foobar.h:
>
> #if CONFIG_FOOBAR
> #define init_foobar(x) do { \
> int f = 2 * (x); \
> foobar_initialize(f); \
> | while (0)
> #else
> #define init_foobar(x) do {} while (0)
> #endif
>
> I don't see any warnings from this, and it provides just
> the right sort of syntax wrapper on the macro init_foobar(),
> forcing it to be a single statement, regardless of context,
> while providing a nested block context for any local variables.
Note your variant doesn't deal with side effects of the argument expression
x (basically none of the equivalent constructions in the kernels do!) which
is why our code in question does something like this:
#if CONFIG_FOOBAR
#define init_foobar(x) do { \
int f = 2 * (x); \
foobar_initialize(f); \
| while (0)
#else
#define init_foobar(x) do { (x); } while (0)
#endif
This can potencially expand into something like:
do { 42; } while(0)
which will result in warnings. The solution is:
#define init_foobar(x) do { (void) (x); } while (0)
Ralf
|