News for hackers. Stuff that matters.
Re:The Preprocessor Iceberg Meme by billforsternz on Thursday July 14, 2022 @05:31PM (#32101701)
Looks good. I wonder why this trick is invariably implemented with "do {" and "} while (0)" and never with "if(1) {" and "} else" ?
Re:The Preprocessor Iceberg Meme by taspeotis on Thursday July 14, 2022 @05:53PM (#32101902)
I think in part because do … while expects a ; at the end so you are obliged to provide one, which makes the macro feel more like a “real” function call.

if … else {} you could omit the ;

Re:The Preprocessor Iceberg Meme by billforsternz on Thursday July 14, 2022 @06:07PM (#32102029)
Good point, thank you. The while (0) demands the expected ; The trailing else hopes for the expected ; but would tolerate a wide range of nonsense instead.