News for hackers. Stuff that matters.
Re:What is your favourite C programming trick? by enqk on Friday October 14, 2011 @02:22PM (#3112300)
do { ... } while (0) makes your macro behave like a statement (i.e. the semicolon is mandatory)
Re:What is your favourite C programming trick? by silentbicycle on Friday October 14, 2011 @02:48PM (#3112409)
Yes. I don't include the trailing semicolon in macro definitions, because I expect the macro to be followed by them:

    MACRO(foo);
Re:What is your favourite C programming trick? by rcfox on Friday October 14, 2011 @02:42PM (#3112380)
({ ... }) does this too. (Is this GCC-specific?)
Re:What is your favourite C programming trick? by mansr on Friday October 14, 2011 @02:56PM (#3112433)
That is a gcc extension. The construct as a whole has the value of the last statement executed within. Usually an inline function is preferable since it achieves the same thing using only standard syntax.