Explanation, please!

Jeff Siegal jbs at fenchurch.MIT.EDU
Fri Aug 26 22:53:49 AEST 1988


In article <2873 at ttrdc.UUCP> levy at ttrdc.UUCP (Daniel R. Levy) writes:
>>[Duff's device loop example from C++ book]
>
>Question:  what if count==0?

The program breaks.  I prefer (and also use, in highly-speed-sensitive
code):

#define duff16(counter, block) \
  switch (counter & 0x0f) { \
   do \
   { \
     counter -= 16; \
     { block; } \
     case 15:	{ block; } \
     case 14:	{ block; } \
     case 13:	{ block; } \
     case 12:	{ block; } \
     case 11:	{ block; } \
     case 10:	{ block; } \
     case 9:	{ block; } \
     case 8:	{ block; } \
     case 7:	{ block; } \
     case 6:	{ block; } \
     case 5:	{ block; } \
     case 4:	{ block; } \
     case 3:	{ block; } \
     case 2:	{ block; } \
     case 1:	{ block; } \
     case 0:    /* null statement */; \
   } while (counter >= 16); \
  }

  duff16(n, *to++ = *from++)

Jeff Siegal



More information about the Comp.lang.c mailing list