棘手的代码 [英] Tricky Code
问题描述
大家好
能否解释一下这段代码。我是从C Faq那里拿来的。
寄存器n =(count + 7)/ 8; / * count> 0假设* /
开关(计数%8)
{
案例0:做{* to = * from ++;
案例7:* to = * from ++;
case 6:* to = * from ++;
case 5:* to = * from ++;
案例4:* to = * from ++;
case 3:* to = * from ++;
case 2:* to = * from ++;
案例1:* to = * from ++;
} while(--n> 0);
}
>
谢谢,
Mohan。
Hi All
Can you please explain this code. I took it from C Faq.
register n = (count + 7) / 8; /* count > 0 assumed */
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);
}
Thanks,
Mohan.
推荐答案
文章< 9b ******* ******************@posting.google.com> ,
Mohanasundaram< mo ************ @ msn.com>写道:
In article <9b*************************@posting.google.com> ,
Mohanasundaram <mo************@msn.com> wrote:
你能解释一下这段代码吗?我是从C Faq那里拿来的。
Can you please explain this code. I took it from C Faq.
这是Duff的设备。谷歌为它,或直接去
< http://www.lysator.liu.se/c/ duffs-device.html > ;.
-
G?ran Larsson http://www.mitt-eget.com/
This is "Duff''s Device". Google for it, or go directly to
< http://www.lysator.liu.se/c/duffs-device.html >.
--
G?ran Larsson http://www.mitt-eget.com/
Mohanasundaram写道:
Mohanasundaram wrote:
请解释一下这段代码。我是从C Faq那里拿来的。
注册n =(count + 7)/ 8; / * count> 0假设* /
切换(计数%8)
{0>案例0:做{* to = * from ++;
case 7:* to = * from ++;
案例6:* to = * from ++;
case 5:* to = * from ++;
case 4:* to = * from ++;
case 3:* to = * from ++;
案例2:* to = * from ++;
case 1:* to = * from ++;
} while(--n> 0);
}
Can you please explain this code. I took it from C Faq.
register n = (count + 7) / 8; /* count > 0 assumed */
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);
}
Google为Duff的设备。
http://www.lysator.liu.se/c/duffs-device.html
http://www.catb.org/~esr/jargon/html ... fs-device.html
Google for Duff''s device.
http://www.lysator.liu.se/c/duffs-device.html
http://www.catb.org/~esr/jargon/html...fs-device.html
mo ************ @ msn.com (Mohanasundaram)写道:
mo************@msn.com (Mohanasundaram) wrote:
能否解释一下这段代码。我是从C Faq那里拿来的。
注册n =(count + 7)/ 8; / * count> 0假设* /
切换(计数%8)
{0>案例0:做{* to = * from ++;
case 7:* to = * from ++;
案例6:* to = * from ++;
case 5:* to = * from ++;
case 4:* to = * from ++;
case 3:* to = * from ++;
案例2:* to = * from ++;
case 1:* to = * from ++;
} while(--n> 0);
}
Can you please explain this code. I took it from C Faq.
register n = (count + 7) / 8; /* count > 0 assumed */
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);
}
好吧,你从C FAQ那里拿到了它,它在
中做得很好,尽可能地解释它,但坦率地说这种代码应该根本不是说b $ b解释了。它只应该由那些完全理解它的人使用,并且可以一目了然地告诉它它的作用,仅仅是
像你这样的凡人和我应该保持良好状态离开*颤抖*。
Richard
Well, you took it from the C FAQ, which does about as good a job at
explaining it as I could, but frankly this kind of code should not be
explained at all. It should only be used by the kind of people who
understand it fully and can tell what it does at a glance, and mere
mortals like you and I should stay well away *shudder*.
Richard
这篇关于棘手的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!