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: Tue, 31 Jul 2012 23:18:44 -0500 Message-ID: <5018AE22.152C@mindspring.com> Date: Wed, 01 Aug 2012 00:18:42 -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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 40 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.107 X-Trace: sv3-kLprDB9TuU0J8eUqViebidzYIKSLVV+Mu4KDATyUgS+d7pXJlfAiw1UkgWkdiGAuQcRwihUIRZB/YE+!z1NsiJqalvUyXnmLB3UxmCjFW419np/FVNVUprvxPY+uV3NTcs7ftCTRnLJWTeQ81Ba7dB6rcudr!EQr5ID7j7wA= 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: 2383 Xref: csiph.com comp.lang.c:24038 Philip Lantz wrote: > > David Brown wrote: > > Les Cargill wrote: > > > Keith Thompson wrote: > > >> Les Cargill writes: > > >>> Type conversions must be made explicit. > > >> > > >> I presume that's meant as advice, not a language rule. > > > > > > Sorry - yes, it's advice. > > > > Good advice. > > > > For my work, it is more than advice - it is a style rule, > > and I enforce > > it with compiler warnings (-Wconversion -Wsign-conversion in gcc). > > Do you really? Would you use casts in situations like these? > 1. char c = 'x'; > 2. int *p = malloc(N * sizeof *p); > 3. free(p); > 4. printf("%c\n", c); > 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. -- pete