Tuesday, July 07, 2009

Duff's Device

It looks like an invalid code, but it is valid! This code portion is known as Duff's device.
    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 ((count -= 8) > 0);
}
More http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html