Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!minya!jc From: jc@minya.UUCP (John Chambers) Newsgroups: comp.unix.programmer Subject: Re: wanted: information on Duff's Device - Message-ID: <445@minya.UUCP> Date: 8 Jan 91 02:14:05 GMT References: <1990Dec24.034911.17074@decuac.dec.com> <1990Dec25.135417.27999@news.cs.indiana.edu> Lines: 78 [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)