🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Chris Sylvain Tue, 21 Oct 1986 15:59
How it got "broke"...
#9628
Author: Chris Sylvain
Date: Tue, 21 Oct 1986 15:59
22 lines
1318 bytes
[]
Why "while( fputc(fgetc(fd), fe) != EOF )" quit working as it
did under both 2.9BSD and Ultrix 1.2 ...
1)  At the end of file, fgetc() returns (int) -1.
2)  fputc() prints (char) -1 and then returns a CHAR not an INT.

Naturally, (int) -1 != (char) -1, so we have a problem.
Question is now: can I deduce that under 2.9BSD and Ultrix
in the above code fragment there is an implied cast, i.e.,
(char) EOF or (int) fputc() ?

[thanks to everyone who responded to the previous posting.]
-- 
--==---==---==--
.. O frabjous day! Callooh! Callay! ..

ARPA: don@umd5.UMD.EDU     BITNET: don%umd5@umd2
UUCP: ..!{ seismo!umcp-cs, ihnp4!rlgvax }!cvl!umd5!don

** WARNING: don@mimsy.UMD.EDU is a different person **
** (umcp-cs and mimsy.umd.edu are the same machine) **
**   -->   Please double-check the address   <--    **
Re: How it got "broke"...
#9632
Author: Chris Torek
Date: Wed, 22 Oct 1986 04:07
22 lines
1381 bytes
In article <1322@umd5> don@umd5 (Chris Sylvain) writes:
>Why "while( fputc(fgetc(fd), fe) != EOF )" quit working as it
>did under both 2.9BSD and Ultrix 1.2 ...

Chances are it never really worked: fputc(EOF, fe) is likely to
put a meta-DEL into file `fe'.

>1)  At the end of file, fgetc() returns (int) -1.
>2)  fputc() prints (char) -1 and then returns a CHAR not an INT.

Actually, fputc returns (unsigned char)c, which turned EOF to 255.

>Naturally, (int) -1 != (char) -1, so we have a problem.

On Ultrix 1.2 Vaxen and 2.9BSD 11s, (int) -1 *is* equal to
(char) -1.  The code is wrong in the first place; fputc is
not supposed to be handed an EOF.  What it does in such cases
is undefined.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@mimsy.umd.edu
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads