Re:What is your favorite C programming trick? (2009)
by deaddodo on Sunday November 22, 2020 @08:21PM
(#25182673)
Semi-experienced C user here, I believe the anonymous block is perfectly adequate here. No idea why they are wrapping it in a single instance do loop, unless they’re unaware of block scoping or I’m unaware of some UB here.
[ Parent
| on HN ]
Re:What is your favorite C programming trick? (2009)
by btrask on Sunday November 22, 2020 @08:29PM
(#25182721)
do {} while(0) is a common idiom for macros in C, because it consumes the trailing semicolon, which a bare {} block doesn't do.
if(x) MACRO();
else something();
expands to if(x) { ... }; // Error!
else something();