Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!wasatch!cdr.utah.edu!moore From: moore%cdr.utah.edu@wasatch.UUCP (Tim Moore) Newsgroups: comp.lang.c Subject: Re: down Message-ID: <787@wasatch.UUCP> Date: 13 Dec 88 06:31:48 GMT References: <45370@yale-celray.yale.UUCP> <2803@hound.UUCP> Sender: news@wasatch.UUCP Reply-To: moore%cdr.utah.edu.UUCP@wasatch.UUCP (Tim Moore) Organization: University of Utah, Computer Science Dept. Lines: 37 In article <2803@hound.UUCP> rkl1@hound.UUCP (K.LAUX) writes: >In article <45370@yale-celray.yale.UUCP>, wald-david@CS.YALE.EDU (david wald) writes: >> You can't assign to a ++ expression. > Of course you can! For example, a simple string copy function: >copy_string (from, to) >char *from; >char *to; >{ > while (*to++ = *from++) > ; ^ | *to is an lvalue. Therefore you can assign to it. Now, the precedence of ++ is higher than *, so the pointer contained in (to) is incremented, but the value of *to++ is still the lvalue that *to represents. That's why the the idiom above works; you're not really assigning to a ++ expression, but to an lvalue. (Well, OK, you are, but you get the idea.) The original message contained: chcnt++ += (c == '\n'); ^ | chcnt is an lvalue here, alright, but the result of chcnt++ is the integer residing in chcnt because "When postfix++ is applied to an lvalue the result is the value of the object referred to by the lvalue"(K&R 1st ed., pg 187), which can not be assigned to. This commandment applies to the *to++ case to(!). to is an lvalue, so to++ evaluates to the pointer that resides in to, which is not an lvalue. The * operator turns the pointer into an lvalue, so assignment can proceed. -Tim Moore 4560 M.E.B. internet:moore@cs.utah.edu University of Utah ABUSENET:{ut-sally,hplabs}!utah-cs!moore Salt Lake City, UT 84112