how is the do loop in the switch code

Discussion in 'C Programming' started by parag_paul@hotmail.com, Mar 31, 2008.

  1. Guest

    void duff(register char *to, register char *from, register int
    count)
    {
    register 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);
    }
    }
     
    , Mar 31, 2008
    #1
    1. Advertising

  2. Eric Sosman Guest

    wrote:
    > void duff(register char *to, register char *from, register int
    > count)
    > {
    > register 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);
    > }
    > }


    Do you have a question?

    Incidentally, despite the suggestive name given to
    the function this is not Duff's Device. Also, there's a
    better way to accomplish what this code does: call
    memcpy (or perhaps memmove) instead.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Mar 31, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    16
    Views:
    3,829
    steve
    Jul 11, 2006
  2. serrand

    break outside a loop and a switch

    serrand, Jan 29, 2006, in forum: C Programming
    Replies:
    14
    Views:
    510
    clayne
    Feb 1, 2006
  3. Cybex
    Replies:
    9
    Views:
    502
    Old Wolf
    Feb 12, 2007
  4. Switch Within A Switch

    , Apr 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    129
    Lasse Reichstein Nielsen
    Apr 22, 2006
  5. Isaac Won
    Replies:
    9
    Views:
    451
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page