Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!cornell!uw-beaver!uw-june!uw-entropy!dataio!bright From: bright@Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: (c = getchar()) Message-ID: <1786@dataio.Data-IO.COM> Date: 14 Dec 88 19:09:09 GMT References: <9142@smoke.BRL.MIL> <45472@yale-celray.yale.UUCP> Reply-To: bright@dataio.Data-IO.COM (Walter Bright) Organization: Data I/O Corporation; Redmond, WA Lines: 13 In article <45472@yale-celray.yale.UUCP> wald-david@CS.YALE.EDU (david wald) writes: >Doesn't the expression (c = getchar()) have type (int) regardless of the >type of c? Or will c being a char really prevent this comparison? 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.