/* The original Duff's device, with unsupported switch/do combination void send(short *to, short *from, int count) { int 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); } } */ /* The original Duff's device, altered for copying void copy(short *to, short *from, int count) { int 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); } } */ /* Using goto instead: */ void copy(short *to, short *from, int count) { int n=(count+7)/8; switch(count%8){ case 0: dolab: *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++; if (--n>0) goto dolab; } } int main(void) { short arr1[3] = {1,2,3}; short arr2[3]; copy(arr2,arr1,3); return arr2[0] + arr2[1] + arr2[2]; }