home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!tlg
- From: tlg@uknet.ac.uk (Tim.Goodwin)
- Newsgroups: comp.lang.c
- Subject: Re: compiler broken?
- Message-ID: <1225@uknet.ac.uk>
- Date: 27 Jul 92 14:43:37 GMT
- References: <1992Jul25.054848.11223@wyvern.twuug.com>
- Organization: UKnet
- Lines: 27
-
- In article <1992Jul25.054848.11223@wyvern.twuug.com>,
- alpha@wyvern.twuug.com (Joe Wright) writes:
- >rdlin() {
- > int i;
- > for (i = 0; i < length && ((record[i] = getc(infile)) != EOF); ++i)
- > ;
- > return i;
- >}
- >
- >It worked fine on my C/80 system but failed on another i486 Unix
- >system. It turned out that if the character read was 0xff it was
- >promoted to -1 (EOF) and caused an 'early' exit. I fixed it:
-
- You don't tell us how `record' is declared, but presumably it's an
- array of char.
-
- It seems slightly odd to me that you should conclude that your compiler
- is broken: getc() returns int (rather than char) precisely so that it
- can communicate the "out-of-band" EOF, as well as any legal char.
-
- You've already found the solution: don't convert the return value of
- getc() to char until after you've compared it with EOF.
-
- Tim.
- --
- The GNU is in fact the legendary and much-berated | ; who am i
- feeping creature - Malcolm Wallace. | uknet.ac.uk!tlg
-