On Thu, 5 Apr 2001, Joseph Carter wrote:

> On Thu, Apr 05, 2001 at 09:06:20AM -0400, Bart Trojanowski wrote:
> > So you ask: "why not just use a { ... } to define a macro".  I don't
> > remember the case for this but I know it's there.  It has to do with a
> > complicated if/else structure where a simple {} breaks.
>
> This doesn't follow in my mind.  I can't think of a case where a { ... }
> would fail, but a do { ... } while (0) would succeed.  The former would
> also save a few keystrokes.

Tim Waugh already stated this one:

#define foo(x) { do_something(x) }

if( condition )
  foo(x);
else
  foo(y);

would produce

if( condition )
  { do_something(x) };
else
  { do_something(y) };

note the semi-colon at the end of {.*}.

This is bad because it forces you to use the foo macro knowing it's a
macro and not a function.

So you say I will use it like this:

if( condition )
  foo(x)
else
  foo(y)

That's just great for this case, but now imagine that on some other
architecture doing foo(x) takes many many lines with recursion and all.
You don't want that to be in a macro so you make a function.  And you get
many many compiler errors on thsi new platform.

Cheers,
Bart.

-- 
        WebSig: http://www.jukie.net/~bart/sig/


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to