Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| 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 | Fri, 16 Mar 2012 23:24:44 -0500 |
| Message-ID | <4F642018.7584@mindspring.com> (permalink) |
| Date | Sat, 17 Mar 2012 00:24:40 -0500 |
| From | pete <pfiland@mindspring.com> |
| 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> <j5j6l9$jd4$1@dont-email.me> <0.f62ca533fe3fac1321b9.20110924024253BST.87zkhuu34y.fsf@bsb.me.uk> <j5ke3c$dp5$1@dont-email.me> <0.4c392657a43f99297620.20110924144538BST.87fwjmt5od.fsf@bsb.me.uk> <j5l1h5$70d$1@dont-email.me> <0.a5ee7a90b39e01baef80.20110924222135BST.87litdskkg.fsf@bsb.me.uk> <j5lqgq$8v1$1@dont-email.me> <87d3eoy3p8.fsf@bazspaz.fatphil.org> <j5nstl$mg4$1@dont-email.me> <ln7h4w30c6.fsf@nuthaus.mib.org> <j5o09d$eul$1@dont-email.me> <ln39fk2r28.fsf@nuthaus.mib.org> <kfn39b4g3py.fsf@x-alumni2.alumni.caltech.edu> <4F202866.5BEA@mindspring.com> <kfnpqdz1kwh.fsf@x-alumni2.alumni.caltech.edu> <4F28C3E1.2C41@mindspring.com> <kfnk42vt3d7.fsf@x-alumni2.alumni.caltech.edu> <4F5BB70E.84B@mindspring.com> <kfnobs0m7zy.fsf@x-alumni2.alumni.caltech.edu> <4F613025.6244@mindspring.com> <kfnbonxl6s8.fsf@x-alumni2.alumni.caltech.edu> |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 96 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 4.154.222.202 |
| X-Trace | sv3-mnZFfQ6siiU7w1U7y3L2abufUMFtmZv1BYNp+Wdwn+2dGm/n06xCS0MXa4t02ju2E1j9yCq8ZRoGxdA!9alx53vbhGUajS+PgKJfiqzYGqZuYQ3laMETuIIGoGM6lVEQnsXl8GHQ6e/Ck4YwGAg8xTE3jGdO!Fs+z22T+iE0= |
| 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 | 5429 |
| Xref | csiph.com comp.lang.c:18830 |
Show key headers only | View raw
Tim Rentsch wrote:
>
> pete <pfiland@mindspring.com> writes:
>
> > Tim Rentsch wrote:
> >>
> >> pete <pfiland@mindspring.com> writes:
> >>
> >> > Tim Rentsch wrote:
> >> >>
> >> >> pete <pfiland@mindspring.com> writes:
> >> >>
> >> >> > Tim Rentsch wrote:
> >> >> >>
> >> >> >> pete <pfiland@mindspring.com> writes:
> >> >> >>
> >> >> >> > Tim Rentsch wrote:
> >> >> >> >
> >> >> >> >> [snip]
> >> >> >
> >> >> > If you're going to say for {char c;}
> >> >> >
> >> >> >>> isalpha( * (unsigned char*) &c )
> >> >> >>>
> >> >> >>> rather than
> >> >> >>>
> >> >> >>> isalpha( (unsigned char ) c )
> >> >> >
> >> >> > then I think we should consider a case where
> >> >> > ( * (unsigned char*) &c )
> >> >> > is different from
> >> >> > ( (unsigned char ) c )
> >> >> > and the only case I can think of,
> >> >> > is where (c) is signed, negative and not twos complement.
> >> >>
> >> >> Right (ignoring padding bits in char, which no sane
> >> >> implementation has), although actually there is one other
> >> >> case, namely a two's complement trap representation. Not
> >> >> very likely perhaps but it is allowed, so for the sake of
> >> >> completeness I think it should be mentioned. (And now it
> >> >> has been...)
> >> >
> >> > Considering that file operations are at the root of this thread:
> >> >
> >> > If char is signed, and char c is assigned a value of (-1), as in
> >> > char c;
> >> > c = -1;
> >> >
> >> > and if (c) is written to a file using fputc,
> >> > then the value written into the file will be ((unsigned char)-1).
> >> >
> >> > If that same byte is read back from the same file using fgetc,
> >> > then the value returned by fgetc will be
> >> > ((int)(unsigned char)-1)
> >> > which is equal to ((unsigned char)c)
> >> > regardless of the representation of negative integers.
> >> >
> >> > The return value of fgetc will be unequal to
> >> > ( * (unsigned char*) &c )
> >> > when negative integers are either sign and magnitude
> >> > or one's complement.
> >>
> >> That's right, of course. Which form should be used depends
> >> on where the bytes came from in the first place -- if they
> >> had been written with fwrite(), for example, then the type
> >> punning form, rather than the ordinary converting form, is
> >> probably a better choice. And conversely.
> >>
> >> I suspect this is all a moot point anyway, since the values
> >> that might be affected most likely will all have the same
> >> characteristics vis-a-vis the <ctype.h> functions. So I
> >> will just say thank you for an interesting discussion.
> >
> > As far as the ctype functions go,
> > if you want use isalpha to give you some idea of
> > whether or not putchar(c) is going to output an alpha,
> > then isalpha((unsigned char)c) is the way to do it,
> > because the value returned by putchar(c)
> > compares equal to ((unsigned char)c).
>
> I don't find this argument persuasive, because in essence it's
> no more than the tautology that 'isalpha( (unsigned char) c )'
> is equal to 'isalpha( (unsigned char) c )'. It is just as true
> that 'isalpha( *(unsigned char*) &c )' will be equal to
> 'isalpha( *(unsigned char*) &c )' (and similarly for putting
> the value through the fputc()/fget() step). That doesn't prove
> anything.
isalpha((unsigned char)c) will tell you
if the output of putchar(c) is an alpha
because putchar(c) is equal to putchar((unsigned char)c).
--
pete
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A very simple parser with scanf & C pozz <pozzugno@gmail.com> - 2011-09-23 07:03 -0700
Re: A very simple parser with scanf & C Nobody <nobody@nowhere.com> - 2011-09-23 18:28 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-23 18:29 +0100
Re: A very simple parser with scanf & C pozz <pozzugno@gmail.com> - 2011-09-23 23:16 +0200
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-24 00:09 +0100
Re: A very simple parser with scanf & C pozz <pozzugno@gmail.com> - 2011-09-24 09:32 +0200
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-23 21:24 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-23 22:00 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-24 00:04 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-24 00:34 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-24 01:00 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-24 02:42 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-24 12:13 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-24 12:25 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-24 15:05 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-24 14:45 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-24 17:45 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-24 22:21 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-25 00:52 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-25 01:54 +0100
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-25 02:51 +0100
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-25 12:22 +0100
Re: A very simple parser with scanf & C Gene <gene.ressler@gmail.com> - 2011-09-25 01:35 -0700
Re: A very simple parser with scanf & C pete <pfiland@mindspring.com> - 2011-09-25 08:41 -0400
Re: A very simple parser with scanf & C Gene <gene.ressler@gmail.com> - 2011-09-25 11:23 -0700
Re: A very simple parser with scanf & C Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-09-25 19:41 +0300
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-25 19:45 +0100
Re: A very simple parser with scanf & C Keith Thompson <kst-u@mib.org> - 2011-09-25 12:10 -0700
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-25 20:43 +0100
Re: A very simple parser with scanf & C James Kuyper <jameskuyper@verizon.net> - 2011-09-25 15:55 -0400
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-26 11:07 +0100
Re: A very simple parser with scanf & C Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-26 11:40 -0400
Re: A very simple parser with scanf & C Keith Thompson <kst-u@mib.org> - 2011-09-26 12:22 -0700
Re: A very simple parser with scanf & C pacman@kosh.dhis.org (Alan Curry) - 2011-09-26 21:19 +0000
Re: A very simple parser with scanf & C Keith Thompson <kst-u@mib.org> - 2011-09-26 16:11 -0700
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-26 23:26 +0100
Re: A very simple parser with scanf & C Keith Thompson <kst-u@mib.org> - 2011-09-26 12:18 -0700
Re: A very simple parser with scanf & C Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-09-27 02:27 +0300
Re: A very simple parser with scanf & C Keith Thompson <kst-u@mib.org> - 2011-09-27 10:06 -0700
Re: A very simple parser with scanf & C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-27 21:10 +0100
Re: A very simple parser with scanf & C Seebs <usenet-nospam@seebs.net> - 2011-09-26 22:59 +0000
Re: A very simple parser with scanf & C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-30 05:18 -0700
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-30 17:06 +0100
Re: A very simple parser with scanf & C Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-25 18:05 -0400
Re: A very simple parser with scanf & C Keith Thompson <kst-u@mib.org> - 2011-09-25 15:30 -0700
Re: A very simple parser with scanf & C Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 14:01 -0800
Re: A very simple parser with scanf & C pete <pfiland@mindspring.com> - 2012-01-25 11:05 -0500
Re: A very simple parser with scanf & C Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 16:01 -0800
Re: A very simple parser with scanf & C pete <pfiland@mindspring.com> - 2012-01-31 23:47 -0500
Re: A very simple parser with scanf & C Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 09:21 -0800
Re: A very simple parser with scanf & C pete <pfiland@mindspring.com> - 2012-03-10 15:18 -0500
Re: A very simple parser with scanf & C Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-13 15:49 -0700
Re: A very simple parser with scanf & C pete <pfiland@mindspring.com> - 2012-03-14 18:56 -0500
Re: A very simple parser with scanf & C Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-15 17:37 -0700
Re: A very simple parser with scanf & C pete <pfiland@mindspring.com> - 2012-03-17 00:24 -0500
Re: A very simple parser with scanf & C Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-21 05:21 -0700
Re: A very simple parser with scanf & C pozz <pozzugno@gmail.com> - 2011-09-23 23:23 +0200
Re: A very simple parser with scanf & C "BartC" <bc@freeuk.com> - 2011-09-23 23:53 +0100
Re: A very simple parser with scanf & C Rui Maciel <rui.maciel@gmail.com> - 2011-09-25 14:07 +0100
csiph-web