Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tektronix.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tektronix!paulh From: paulh@tektronix.UUCP (Paul Hoefling) Newsgroups: net.lang.c Subject: C question Message-ID: <5272@tektronix.UUCP> Date: Fri, 5-Apr-85 13:24:45 EST Article-I.D.: tektroni.5272 Posted: Fri Apr 5 13:24:45 1985 Date-Received: Sat, 6-Apr-85 07:47:07 EST Organization: Tektronix, Beaverton OR Lines: 56 I was trying to send this to Dennis Ritchie, but I can't seem to find a path to him. So, I'll open it up for net discussion (and flames :-) ). We've got a raging controversy going on here at Tektronix, and I thought that I would appeal to you for an 'official' opinion. --------------------------- The controversy: An inexperienced C programmer wrote a program containing the following: x = x++; Assuming that x originally had the value 5, what should the value be after execution of the above expression ? --------------------------- The arguments: In favor of 5: According to the operator precedence table in K&R on page 49, the ++ operator has higher precedence than the = operator. Hence the sequence of operations should be: evaluate x (value == 5) increment x (x now == 6) assign the computed value to x (x now == 5 again) In favor of 6: In K&R on page 42, the text says: "But the expression ++n increments n *before* using its value, while n++ increments n *after* its value has been used." Hence, the sequence of operations should be: evaluate x (value == 5) assign the computed value to x (x still == 5) increment x (x now == 6) --------------------------- Therefore, if the compiler writer follows the precedence table, 5 wins, and if s/he follows the text, either could win. Is there an 'official' opinion, and if so, what is it ? We are most interested in your response. I would like to point out that the various compilers around here have been tried, and we have 1 vote for 6 (our 4.2BSD compiler), and 3 votes for 5 (various microprocessor compilers). If you send mail to me at ...!tektronix!paulh, I will collect the responses and summarize for the net. If Dennis Ritchie is out there somewhere, I would *really* appreciate his opinion on the subject. -- Paul Hoefling (...!tektronix!paulh) Information Pack Rat