Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.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: Sat, 08 Sep 2012 09:13:49 -0500 Message-ID: <504B529D.35AA@mindspring.com> Date: Sat, 08 Sep 2012 10:13:49 -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: Restricted unsigned integer range would have been better? References: <5011E247.1F7B@mindspring.com> <5012954D.20C@mindspring.com> <5018AE22.152C@mindspring.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 37 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.223.191 X-Trace: sv3-wG554bTgxUPRPLLhXUFNhxsuik017GZTPLiLMuhXiem4moV0P6sdLBNDtIqMDPHosE+1e7fs+E7COXF!gmquy3mU+RNXr7bOjwGmJ4YQ0J+5LwAL+A1aGCsrJUx3YNHBKzO9AODj4gc1yKmaddqMeaMnhVba!APrtCCUTA7Q= 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: 2313 Xref: csiph.com comp.lang.c:26141 Tim Rentsch wrote: > > pete writes: > > > Philip Lantz wrote: > >> [..snip..snip..] > >> > >> Do you really? Would you use casts in situations like these? > >> 5. while (*s != '\0') > >> n = n * 10 + (*s - '0'); > >> > >> I would find them to be undesirable clutter. > > > > I was thinking the same thing. > > > > And I think you meant to imply > > that (*s) is an expression of type char. > > > > 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. -- pete