Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looks good. I wonder why this trick is invariably implemented with "do {" and "} while (0)" and never with "if(1) {" and "} else" ?


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 ;


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: