Re: how is the do loop in the switch code



parag_paul@xxxxxxxxxxx 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
esosman@xxxxxxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: anti-aliasing
    ... because memcpy() is defined as UB if passed aliased ... The snag is that memmove() is called memmove. ... If I was reviewing the code and the programmer could not either prove the regions would never overlap or that it was valid that the regions overlapped and it was handled properly I would reject it. ...
    (comp.lang.c)
  • Re: anti-aliasing
    ... that to allow aliases and efficinet copying of non-aliases. ... because memcpy() is defined as UB if passed aliased ... As a general rule is is better to avoid bugs than speed ... If you want the memmove() behaviour, use memmove, and don't ...
    (comp.lang.c)
  • Re: set double array to 0.0
    ... > The functions memmove() and memcpy() both copy data from the source buffer ... > guaranteed to copy overlapping buffers correctly. ... > I had a look at the optimized assembler source code in the VC runtime ...
    (comp.lang.c)
  • Re: anti-aliasing
    ... The snag is that memmove() is called memmove. ... Psychology matters. ... memmovewere called memcpy() and memcpyfast_memcpy, ... incorrectly so the programmer learns to use it properly. ...
    (comp.lang.c)
  • Re: malloc and free
    ... I don't find memmove any more obscure than memcpy, ... Christopher over the memcpy/malloc/free version written by Arthur is ...
    (comp.lang.c)