C Puzzle #13

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);
      }
  }
Is the above valid C code? If so, what is it trying to acheive and why would anyone do something like the above?

Answer is here

2 comments:

  1. Nice Logic, it takes 1/4th of the time of strncpy() function

    ReplyDelete
    Replies
    1. !!!!.. i think the assembly code of strncpy/memcpy would be rather straight forward and quick...

      Delete

Your answer for the question

Related Posts Plugin for WordPress, Blogger...