Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 06 Jun 2012 08:22:17 -0500 Message-ID: <4FCF598A.463@mindspring.com> Date: Wed, 06 Jun 2012 09:22:18 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) References: <7e54cf3c-d514-407b-a9b6-c0009589d242@ra8g2000pbc.googlegroups.com> <313ed2ec-dece-43f5-b2b3-1c5a63229add@t1g2000pbl.googlegroups.com> <0.c82e19170840b2237717.20120606131443BST.87bokwbpsc.fsf@bsb.me.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 68 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.223.87 X-Trace: sv3-vCUO9kkAmjEjt9BiTQhX2Xjf+KVNBbaJ53jdaZ1Cj0rzXWmHKmcuTGMVEhzTx83kB/1DPcsF13TVsBB!/mgvNLMJZewJRdZvmalPUog2pMJi+Lsvi9A1cynNUO93R9zIbakFTu+n7vlLZ16QPe3LRH0TqOtk!WMveiOnf X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3532 Xref: csiph.com comp.lang.c:21905 Ben Bacarisse wrote: > > mike3 writes: > > > On May 31, 5:39 pm, mike3 wrote: > >> On May 29, 11:44 pm, mike3 wrote: > > > > > > I've been wondering about this. _Why_ was a GOTO used in this > > program? How could one be used in _such a high-profile program > > like that_? And it's not just a lone GOTO or a few here and there, > > as I said, this program is infected with a serious case of GOTOitis... > > You'd have to ask the people who wrote it. > > Some of the code looks extraordinary to me. Whilst the vast majority of > goto's are clearly of the "error cleanup" sort, they are not all like > that. For example there is this pattern: > > cmsgp = CMSG_FIRSTHDR(msg); > while (cmsgp != NULL) { > socket_log(...); > > #ifdef ISC_PLATFORM_HAVEIN6PKTINFO > if (...) { > /* stuff */ > goto next; > } > #endif > > #ifdef SO_TIMESTAMP > if (...) { > /* stuff */ > goto next; > } > #endif > next: > cmsgp = CMSG_NXTHDR(msg, cmsgp); > } > > Why is this not just a for loop? > Failing that, why not just remove the > label and the goto's? Maybe this is a fossilised relic of some much > more complex code. > > Although there may well be a reason > the code ended up like this, I hope > everyone agrees that it would be odd (to say the least) > to write it like this from scratch. It may be the case that it is, or was, somewhat common for expert proffesional programmers to have accomplished a lot of proffesional programming work before they became experts. I recall many many years ago, showing some crappy looking code to my new boss, and him telling me that because of time constraints I would soon be writing crappy looking code too. And he was right. They hired me when they needed a programmer right away, and I didn't know C or good writing style nearly as well as I do now, and because of time constraints, I had to program quickly. -- pete