Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!hao!oddjob!mimsy!umd5!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: ungetc Message-ID: <6612@brl-smoke.ARPA> Date: Fri, 30-Oct-87 00:06:17 EST Article-I.D.: brl-smok.6612 Posted: Fri Oct 30 00:06:17 1987 Date-Received: Wed, 4-Nov-87 05:43:55 EST References: <6592@brl-smoke.ARPA> <165600020@uiucdcsb> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 26 In article <165600020@uiucdcsb> mccaugh@uiucdcsb.cs.uiuc.edu writes: > Not sure why you want an int for first argument to 'ungetc' -- Harbison&Steele > report char, not int (page 316). Also, the stream must have been opened for > input and buffered, and one character must already have been read to be pushed > back. Perhaps you were concerned about the return-value, which is (int) c. Al- > so, trying to push EOF has no effect and just returns EOF as value. Excuse me, but good as it is, H&S is not the C language/library definition, nor has it been generally considered as one. When I state (for example) that ungetc() takes an int as its first argument, you can bet that I'm quoting from the draft proposed American National Standard for C, which is expected to also become an ISO standard. A former "standard" is K&R (Kernighan & Ritchie: The C Programming Language), which is quite a bit out of date at this point. (I believe it was the first book about C.) The proposed official ungetc() definition takes an int first argument, converts it to an unsigned char, and pushes the result back onto the input stream specified by the second argument. It returns an int value containing the character pushed back (after conversion) if successful, otherwise EOF. The stream need not be buffered, and no characters need have been read before the pushback. Pushback is discarded under certain specified circumstances (e.g., a call to a file positioning function). Some aspects of the official definition are not properly reflected by some current implementations, so it is unwise to rely too much on the more subtle semantics of ungetc() for the time being.