Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ukma!usenet.ins.cwru.edu!agate!ocf!rgm From: rgm@ocf.berkeley.edu (Rob Menke) Newsgroups: comp.lang.c Subject: Re: post-decrement quirk? Message-ID: Date: 18 Jun 91 02:45:32 GMT References: <1991Jun17.230838.9628@auto-trol.com> Sender: usenet@agate.berkeley.edu (USENET Administrator) Distribution: usa Organization: TEAM CS -- Making Tomorrow's Mistakes Today! Lines: 19 In-Reply-To: julbro@auto-trol.com's message of Mon, 17 Jun 1991 23: 08:38 GMT In article <1991Jun17.230838.9628@auto-trol.com> julbro@auto-trol.com (Julie Brown) writes: Can anyone explain to me why the following does not work (at least on the Sun): q = q--; It's quite simple: set-value ('=') has a lower precedence than post-decrement. So, the expression on the RHS is evaluated (it equals 'q'), q is decremented, then q is set to the stored value from the RHS. Net result: no decrement. You're better off with: q = (q > 0) ? q - 1 : 0; -- "It is a pity that you Autobots die so | Robert Menke easily... otherwise one might get a | rgm@OCF.berkeley.edu sense of satisfaction..." | ...!ucbvax!OCF!rgm