Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!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: Tue, 10 May 2011 02:53:19 -0500 Message-ID: <4DC8EEED.139F@mindspring.com> Date: Tue, 10 May 2011 03:53:17 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.unix.programmer,comp.lang.c Subject: Re: Avoiding recursive stack overflow in C on Unix/Linux? References: <2f33e674-b127-4c35-89b5-dcbf564f3aab@h36g2000pro.googlegroups.com> <92reltF51pU8@mid.individual.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 56 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.220.173 X-Trace: sv3-mkAnTgnIyABQWz/BLfqT9+j+TqNHAhXoByI928NhFpyh1yi2eK5ZQEcy8icYoKc3hpS4bG/qAhlXz5A!vK3M1ACYhPnEsCqYRDEpiTpSBm/2BgKtTiEwg0Xujpz+pIQtIOzU6KRa7bb1UGiGZg/5GS5n4pxp!aveqR4u+AMU= 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: 3358 Xref: x330-a1.tempe.blueboxinc.net comp.unix.programmer:470 comp.lang.c:3670 Ian Collins wrote: > > On 05/10/11 12:11 PM, Michael Press wrote: > > In article > > <2f33e674-b127-4c35-89b5-dcbf564f3aab@h36g2000pro.googlegroups.com>, > > Joshua Maurice wrote: > > > >> On May 9, 3:05 pm, Michael Press wrote: > >>> There are good reasons to write it oneself. When I want > >>> a binary search I simply write it on the fly; and embed > >>> whatever I want to do with the search result right there. > >>> > >>> It takes as long or longer to write the interfaces to a > >>> library binary search as it does to write one that does > >>> exactly what I want. > >> > >> I politely disagree, > >> and I must express my extreme disbelief at this > >> statement that you can write a good correct binary search algorithm > >> faster than you can use C++ std::map, > >> or C++ std::lower_bound, et al. I can write a good binary search algorithm faster than I can use C++ std::map, or C++ std::lower_bound, et al, because I don't know C++. > > Does the library write your compare routine > > and unit test it for me? > > If it has to be written, > you have to write and test the compare routine > whether you use a library for the search or not. > > > Does the library > > routine inline the code that examines the > > return and executed the action dependent on > > the return value? > > That's the compiler's job, not the library's. > > > Does the library return > > a value in exactly the form I want? > > How many forms of true and false are there? bsearch either returns NULL or returns a pointer to an element of an array. It is also possible to want a binary search which returns a pointer to the first occurance in the array or to want a binary search which returns a pointer to the last occurance in the array. -- pete