Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!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: Sun, 15 May 2011 19:15:00 -0500 Message-ID: <4DD06C8B.319E@mindspring.com> Date: Sun, 15 May 2011 20:15:07 -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: I need help References: <04ee4fd1-29ef-4640-a906-22055187c1e4@glegroupsg2000goo.googlegroups.com> <4DD065AF.184F@mindspring.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 45 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.218.145 X-Trace: sv3-PX154QdcTbBWoaOyCmKP2E58JmI897ZwiSiQgKVtyn1IAZB27vHNqtheHOVn4xvbMu9XlX/T/juPuyX!o1OTmL6B2TaLHo+cLg4GMPRPKMZ9gG+a3Aa28yTxb2u4Y+af7/U+9XbiJMOZogJZlizKmkSpMqUG!dC4ry51Mt1I= 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: 2622 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:4040 pete wrote: > > Eric Sosman wrote: > > > > On 5/15/2011 5:37 PM, sandeep wrote: > > > Eric Sosman writes: > > >> char *space = strchr(karmarkar, ' '); if (space == NULL) > > >> printf ("No spaces\n"); > > >> else > > >> printf ("First space is at position %u\n", > > >> (unsigned)(space - karmarkar)); > > > > > > This could give the wrong answer on implementations > > > where PTRDIFF_MAX > UINT_MAX. > > > > Thank you so very, very much for this helpful observation, > > guaranteed to clarify matters for the O.P. > > sandeep is wrong. > The context (snipped by sandeep) > for which your code was written, is this: > char* karmarkar = "Karmarkar 958572"; > > And in that context, there is no way that the difference > between (space) and (karmarkar) can excede either UINT_MAX > or PTRDIFF_MAX (which would be a different C trivia point). I should have been more clear. Whether or not (PTRDIFF_MAX > UINT_MAX) is true, is irrelevant. This code cannot give the wrong answer. What matters, in terms of whether or not the code is undefined, is whether or not (space - karmarkar) is representable as a ptrdiff_t value. Since (space - karmarkar) is representable as a ptrdiff_t value, then what matters, in terms of whether or not the code outputs the correct answer, is whether or not (space - karmarkar) is less than or equal to UINT_MAX. -- pete