Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!xanth!nic.MR.NET!umn-d-ub!rutgers!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: (c = getchar()) Message-ID: <8543@alice.UUCP> Date: 15 Dec 88 03:16:40 GMT References: <9142@smoke.BRL.MIL> <1786@dataio.Data-IO.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 19 In article <1786@dataio.Data-IO.COM>, bright@Data-IO.COM (Walter Bright) writes: -> If c is of type char, then: -> (c = getchar()) -> is equivalent to: -> (int)(c = (char) getchar()) -> What's happening is that the rvalue (getchar()) is cast to be the same -> type as the lvalue (c). The value of the assignment expression is the -> value of (c) after the integral promotions are performed, i.e. after (c) -> is converted to an int. Thus, the int result of getchar() was truncated to -> be a char and then promoted back to an int, in the process losing anything -> that was in the bits beyond the char. Indeed. At least that's what's supposed to happen. Sometimes other things happen, though. See page 70 of ``C Traps and Pitfalls'' for details. -- --Andrew Koenig ark@europa.att.com