From: Bill Kelly Date: 2003-12-30T07:16:44+09:00 Subject: Re: Question about Ruby implementation Hi, From: "Jamis Buck" > > [...] I have a question now about some of > the macros I've seen: why do some macros wrap their contents in a "do { > ... } while(0)"? Is this preferable to simply wrapping them in curly > braces ("{...}")? Is it simply a matter of matz's programming style, or > is there some subtler issue in effect here? It's a 'C' language idiom. It makes a terminating semi-colon a required part of the syntax, which helps avoid mistakes with the one-liner form of (for instance) if/else statements, and such. #define THING1 {blah()} #define THING2 do{blah()}while(0) if (rand() & 1) THING1(); else THING2(); ...note problem with THING1() usage, given the extraneous semi-colon... HTH, Regards, Bill