Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!sri-spam!mordor!lll-tis!ptsfa!ihnp4!homxb!houxm!hropus!ka From: ka@hropus.UUCP (Kenneth Almquist) Newsgroups: comp.lang.c Subject: Re: Style [++i vs i++] Message-ID: <1183@hropus.UUCP> Date: Fri, 24-Jul-87 16:10:15 EDT Article-I.D.: hropus.1183 Posted: Fri Jul 24 16:10:15 1987 Date-Received: Tue, 28-Jul-87 03:10:30 EDT References: <17310@amdcad.AMD.COM> <2159@emory.uucp> Organization: Bell Labs, Holmdel, NJ Lines: 41 > I just tried this on my Integrated Solutions w/ 4.2BSD: > > main() > { > int i; > > i++, 5; > } > > and I got this (useless crud deleted): > > movl fp@(-4),d0 ;*********** Not necessary > addql #1,fp@(-4) > moveq #5,d0 > > I strongly suspect that this machine's compiler is PCC. This bug is understandable based upon the way PCC generates code. PCC looks up operators in the code generation table in the file table.c. In generating the code for the statement "i++;", PCC will try to generate code for the "++" operator for side effects only. If Integrated Solutions forgot to provide an entry in the code table to allow PCC to do this, PCC will compute the value of "i++" in a register rather than giving up entirely. I expect that this shouldn't be too hard to fix if you have source. Look in the file table.c. You should find entries for INCR and DECR. If there are no entries for these operators with FOREFF set, add them. I don't know what all the fields in the table mean, but you should be able to guess close enough by looking at the existing entries for INCR and DECR if you have no documentation. The reason Integrated Solutions didn't catch this bug is that the entries in the code table for INCR and DECR are rarely used. PCC has a routine which will go through an expression, replace all occurances of "i++" with "i", and then tack on an "i += n" to the end of the expression, where n is number of occurances of "i++". This is inhibited by operators which place restrictions on the expression evaluation order. In the code quoted above, the routine could not perform its function because the expression contained a comma operator. Kenneth Almquist