From: Jamis Buck Date: 2003-12-30T07:22:01+09:00 Subject: Re: Question about Ruby implementation Dave Thomas wrote: > > It's good style in general. Consider > > if (something) > MACRO; > > and > > if (something) > MACRO; > else > puts("hello"); > > With just {}'s around the macro, the second case wouldn't compile > (because of the semicolon). > > > Cheers > > > Dave > > Yah, I understand that, I think. But why have MACRO wrap its contents in a "do{...}while(0)", instead of just "{...}"? In other words, is there a compelling reason to do this: #define MACRO(x) \ do { \ x \ } while(0) instead of this: #define MACRO(x) \ { \ x \ } I'm just curious -- if it just comes down to a personal preference thing, that's fine. But if there is a good reason for doing one over the other, I'd like to know. Thanks. :) -- Jamis Buck jgb3@email.byu.edu ruby -h | ruby -e 'a=[];readlines.join.scan(/-(.)\[e|Kk(\S*)|le.l(..)e|#!(\S*)/) {|r| a << r.compact.first };puts "\n>#{a.join(%q/ /)}<\n\n"'