Notice how the do while is sandwiched in the case 0, and others cases lie within this do while loop , this kind of code is called Duff's Device after the guy who wrote this kind of code for the first time . I couldnt believe my eyes , I ran it through the debugger to follow the flow of the code , I adapted the code below from the usenet article where this kind of code was first presented , I just cleaned up the indentation in an attempt to understand what is happening .
http://groups.google.com/groups?selm=2748%40alice.UUCP
Code:void send( int *to, int *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); } } int main(void) { int a=3,b=4; send(&a,&b,3); printf("a=%d b=%d",a,b); return 0; }



LinkBack URL
About LinkBacks


