What does the following example do?
问题描述:
What does the following example do?
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);
}
}
//The C++ Programming Language (Third Edition) CH6 - 15
答
主要目的是把从from开始拷贝数据到to.
拷贝数量是 ( ( ( count + 7 ) % 8 ) - 1 ) * 8 + ( count % 8 ) 个元素.
第一次从count%8开始,依次执行 case count%8-1,case count%8-2 ..到
case 1,
然后循环n-1次,执行 do {} 中间的代码.