开发者

Is the above valid C code? [closed]

开发者 https://www.devze.com 2023-03-13 04:00 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I was given this question in my college in a programming contest...

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: *t开发者_如何学JAVAo++ = *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?


Yep, it's known as Duff's device.

As far as I can remember it was written by someone doing special effects for a movie (Star Wars or something like that). It was written this way to get maximum performance.

But, would I suggest to write code like this: NO.

Keep your code readable!

0

精彩评论

暂无评论...
验证码 换一张
取 消