home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11636 < prev    next >
Encoding:
Text File  |  1992-07-27  |  918 b   |  38 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!sun-barr!ames!daffodil!wyvern!alpha
  3. From: alpha@wyvern.twuug.com (Joe Wright)
  4. Subject: compiler broken?
  5. Message-ID: <1992Jul25.054848.11223@wyvern.twuug.com>
  6. Organization: Box 68621, Virginia Beach, 23455
  7. X-Newsreader: Tin 1.1 PL4
  8. Date: Sat, 25 Jul 1992 05:48:48 GMT
  9. Lines: 27
  10.  
  11. Is this 'normal'?  I wrote the following routine some days ago
  12. on my C/80 system:
  13.  
  14. rdlin() {
  15.     int i;
  16.     for (i = 0; i < length && ((record[i] = getc(infile)) != EOF); ++i)
  17.         ;
  18.     return i;
  19. }
  20.  
  21. It worked fine on my C/80 system but failed on another i486 Unix
  22. system.  It turned out that if the character read was 0xff it was
  23. promoted to -1 (EOF) and caused an 'early' exit.  I fixed it:
  24.  
  25. rdlin() {
  26.     int c, i;
  27.     for (i = 0; i < length; ++i) {
  28.         if ((c = getc(infile)) == EOF)
  29.             break;
  30.         record[i] = c;
  31.     }
  32.     return i;
  33. }
  34.  
  35. Question:  Is the Unix compiler broken?  
  36. -- 
  37. Joe Wright  alpha@wyvern.twuug.com    
  38.