Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.imp.ch!newsreader4.netcologne.de!news.netcologne.de!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.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: Wed, 25 Jan 2012 10:05:55 -0600 Message-ID: <4F202866.5BEA@mindspring.com> Date: Wed, 25 Jan 2012 11:05:58 -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: A very simple parser with scanf & C References: <88940b22-00a2-4d6e-81e1-51214b073a96@fe21g2000vbb.googlegroups.com> <0.7e9ca0c91e324ac14acd.20110923220028BST.87y5xfug7n.fsf@bsb.me.uk> <0.f03c4aaff4700164ddab.20110924003423BST.8762kivnnk.fsf@bsb.me.uk> <0.f62ca533fe3fac1321b9.20110924024253BST.87zkhuu34y.fsf@bsb.me.uk> <0.4c392657a43f99297620.20110924144538BST.87fwjmt5od.fsf@bsb.me.uk> <0.a5ee7a90b39e01baef80.20110924222135BST.87litdskkg.fsf@bsb.me.uk> <87d3eoy3p8.fsf@bazspaz.fatphil.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 50 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.216.133 X-Trace: sv3-HXZOVkgLhcfAwYMT581QQwKKM3uuKYlSGjQZgRxKFrff70FZAtH3NnSrG2UFgTJhH1zSLiLqSswIOgR!pk9x32RJzpYGcpEQDKWyD3nxvy8EYX8tdtyupRgD+HzuvO9DJeg2263EIERCsAZAZRcLlt5WQVpV!H2jCXZUrmek= 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: 3130 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:16200 Tim Rentsch wrote: > My understanding is that a cast to (unsigned char) may not > give exactly the right behavior. In particular, if we have > a variable 'char c;' then to call a function like 'isalpha()' > we need to do > > isalpha( * (unsigned char*) &c ) > > rather than > > isalpha( (unsigned char ) c ) > > to get exactly the same behavior as happens for getchar(), etc. > > Of course, on most current machines these two methods give > the same results, but as a matter of correctness the first > form is the better one. Right? I don't think so. If you were to output the value of (c) using fputc, then the return value of the function call would be ((int)(unsigned char)c). Th value of (c) "converted to unsigned char" is ((unsigned char)c). N869 4.9.7.3 The fputc function Synopsis #include int fputc(int c, FILE *stream); Description The fputc function writes the character specified by c (converted to an unsigned char ) ... Also, isalpha also has to be able to work with arguments which may be constant expressions that don't have addresses. Given #define NEG_A ('A' - 1 - (unsigned char)-1) then isalpha ((unsigned char)NEG_A) should return nonzero and putchar((unsigned char)NEG_A) should return ('A') -- pete