wanted: information on Duff's Device -
John Chambers
jc at minya.UUCP
Tue Jan 8 13:14:05 AEST 1991
[History of "Duff's Device"]
> send(to, from, count)
> register short *to, *from;
> register count;
> {
> register 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);
> }
> }
>
> Disgusting, no? But it compiles and runs just fine. I feel a combination
> of pride and revulsion at this discovery. If no one's thought of it before,
> I think I'll name it after myself.
Uh, why is this disgusting? It strikes me as simple and elegant. I have
severe doubts that any minimally-competent C programm would have even the
slightest trouble understanding it. It's not tricky, convoluted, confusing,
or anything else negative. So why would someone object to it?
Myself, I think that people object to simple, elegant things just because
they are simple and elegant [but I don't claim to read minds. ;-]
What I was hoping for was a simple, elegant solution that involved a goto.
Now THAT would offend people! Oh, well, maybe next time.
Of course, I would have put the while before the loop, but then, I'm rather
paranoid. For n==0, the above code will copy 8 bytes, which could cause a
SEG fault, and guess whose routine dbx/sbd/whatever would finger?
[To satisfy the line count daemon.]
--
Zippy-Says: Imagine ... a world without clothing folds, chiaroscuro, or marital difficulties ...
Home: 1-617-484-6393 Work: 1-508-952-3274
Uucp: ...!{harvard.edu,ima.com,eddie.mit.edu,ora.com}!minya!jc (John Chambers)
Uucp-map: minya adelie(DEAD)
More information about the Comp.unix.programmer
mailing list