5 ms·
Looks good. I wonder why this trick is invariably implemented with "do {" and "} while (0)" and never with "if(1) {" and "} else" ?
by billforsternz 4y ago
Looks good. I wonder why this trick is invariably implemented with "do {" and "} while (0)" and never with "if(1) {" and "} else" ?
- taspeotis 4y agoI 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 ;
- billforsternz 4y agoGood 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.
- deleted 4y ago[deleted]