"Brett Thompson!" wrote:
> #define spin_lock_init(x) do { (x)->lock = 0; } while(0)
>
> How come a do-while loop (or, erm, in this case, a
> non-loop?) used? My professor thinks that it's to prevent spin_lock_init
> from being used in expressions in which order of operations could mess
> things up, but if so, wouldn't { (x)->lock = 0; } also do the trick?
do { ... } while (0) is the standard way of enclosing a block of code
in a macro. You are correct that you only need "{ ... }" for most
situations. I can't remember if the "do/while" is a relic of old K&R
compiler compatibility habits, or if there are a few semantic situations
which exist today that require do/while not just {}.
Jeff
-- Jeff Garzik | Liberty is always dangerous, but Building 1024 | it is the safest thing we have. MandrakeSoft, Inc. | -- Harry Emerson Fosdick- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:27 EST