[lkml]   [2001]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: asm/unistd.h
On Thu, 5 Apr 2001, Sardañons, Eliel wrote:

> I'm taking a look at the linux code and I don't understand how do you
> programm...mmm (?) may be i'm a stupid why in include/asm/unistd.h in some
> macros you use this:
> do {
> ...
> } while (0)

This is a very useful trick.

If you define a macro such as:

#define foo(x) do_one(x); do_two(x); do_three(x)

you may later be compelled to call it in an if statement:


note that it would not do what you want as it will only execute do_one(x)
conditionally but do_two(x) and do_three(x) would always be done.

However a do{ ... } while(0) is a nice convenient block which is
guaranteed to execute once. The compiler (with a -O flag) will not
generate any extra code for the do{}while(0) so its just a macro building

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.



To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:24    [W:0.071 / U:3.180 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site