linux-mips
[Top] [All Lists]

Re: [PATCH] include/asm-mips/pci.h

To: Paul Jackson <pj@engr.sgi.com>
Subject: Re: [PATCH] include/asm-mips/pci.h
From: Ralf Baechle <ralf@oss.sgi.com>
Date: Thu, 20 Jun 2002 12:25:26 +0200
Cc: William Jhun <wjhun@ayrnetworks.com>, linux-mips@oss.sgi.com
In-reply-to: <Pine.LNX.4.44.0206191326560.18638-100000@turbo-linux.engr.sgi.com>; from pj@engr.sgi.com on Wed, Jun 19, 2002 at 01:38:52PM -0700
References: <20020619112207.B6057@ayrnetworks.com> <Pine.LNX.4.44.0206191326560.18638-100000@turbo-linux.engr.sgi.com>
Sender: owner-linux-mips@oss.sgi.com
User-agent: Mutt/1.2.5.1i
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

<Prev in Thread] Current Thread [Next in Thread>