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. Advertisements

  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. Advertisements

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:
    4,641
    steve
    Jul 11, 2006
  2. serrand

    break outside a loop and a switch

    serrand, Jan 29, 2006, in forum: C Programming
    Replies:
    14
    Views:
    605
    clayne
    Feb 1, 2006
  3. Cybex
    Replies:
    9
    Views:
    715
    Old Wolf
    Feb 12, 2007
  4. mahantesh varavattekar
    Replies:
    1
    Views:
    299
    Laurent Claessens
    Jun 23, 2011
  5. Carter Cheng

    YARV bytecode switch loop

    Carter Cheng, Mar 29, 2011, in forum: Ruby
    Replies:
    3
    Views:
    185
    Carter Cheng
    Mar 30, 2011
  6. perl implicit loop switch

    , Feb 26, 2009, in forum: Perl Misc
    Replies:
    3
    Views:
    164
    Darren Dunham
    Mar 3, 2009
  7. Switch Within A Switch

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