home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11639 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  1.2 KB

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