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: Mon, 17 Dec 2012 18:51:00 -0600 Message-ID: <50CFBDF9.39F5@mindspring.com> Date: Mon, 17 Dec 2012 19:51:05 -0500 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: Restricted unsigned integer range would have been better? References: <5011E247.1F7B@mindspring.com> <5012954D.20C@mindspring.com> <5018AE22.152C@mindspring.com> <504B529D.35AA@mindspring.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 64 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.63 X-Trace: sv3-hHf7ocHFC/59oVlmzPTMqmlRGTSwGC+g4GMexRkH6xsmmGjaEt+EbfHhI6t9m1Nqnw1Il9+7Qhon2bm!XftY47GJ3r3flJjI7p2VdhO2duggTenOi2UmNFrKi+HjNQVxQw1GbyUkc/jX5xInLAIrkF7Cu5B/!crnA3XOdpw== 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: 3544 Xref: csiph.com comp.lang.c:29451 Tim Rentsch wrote: > > Philip Lantz writes: > > > pete wrote: > >> Tim Rentsch wrote: > >> > pete writes: > >> > > Philip Lantz wrote: > >> > >> [..snip..snip..] > >> > >> > >> > >> 5. while (*s != '\0') > >> > >> n = n * 10 + (*s - '0'); > >> > >> > >> > > If n is of type int and also not negative, > >> > > then you could write without having to use parentheses > >> > > n = n * 10 - '0' + *s; > >> > > with no possibility of overflow. > >> > > >> > Is there some reason you wouldn't write > >> > > >> > n = *s-'0' + n*10; /* or add more spacing, if preferred */ > >> > > >> > ? > >> > >> > >> Not any good reason. > >> > >> I have an aesthetic preference > >> for writing the more strongly associated > >> arithmetic operators first. > > > > I think aesthetics *is* a good reason > > for writing code a certain way. > > [snip elaboration] > > Sure, but not the only one. In writing, for example, it is my > preference not to split an infinitive. My preference is to not split an infinitive. No, wait ..., I told that wrong ;) > Sometimes, though, it's > awkward to just blindly follow that rule. In the particular > case here (ie, in assigning to n), IMO there is very little > difference aesthetically between the two writings, and the > second one even might be a little easier to digest when reading > it. Partly I was curious how much of the choice was an actual > conscious process and how much was doing things a particular way > just because that's the way the author is used to doing them. I frequently imagine a processor with an accumulator and I write the values in the order that I imagine them being accessed. But sometimes, I'll write something like digit = n - 10 * tenth; even though digit = tenth * -10 + n; fits that rule better, just because I prefer the looks of digit = n - 10 * tenth; and then I have to say "I don't really know why". -- pete