3 ms·
For C it should most certainly be the ability to interleave the switch-case and a block statement as per Duff's device: register n = (count + 7) / 8; s
by huhtenberg 14y ago
For C it should most certainly be the ability to interleave the switch-case and a block statement as per Duff's device:
register n = (count + 7) / 8;
switch(count % 8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while(--n > 0);
}
[0] http://en.wikipedia.org/wiki/Duff%27s_device http://en.wikipedia.org/wiki/Duff%27s_device
- niggler 14y agoI wouldn't necessarily call this strange if you think about how this directly translates to assembly instructions.
- podperson 14y agoIt's pretty strange nonetheless that it compiles at all. Underlying it is that a switch statement isn't a proper control structure but syntax sugar for goto.
- smsm42 14y agowhile() loops are really syntax sugar for goto too. And whole C is arguably just a syntax sugar for assembler :) That's why we use it.
- podperson 14y agoThey're not syntax sugar for goto the way switch is though. You can't pull stunts like that with two intermingled while loops because a while loop operates on a single block.