Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!mit-eddie!ll-xn!ames!amdcad!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Style [++i vs i++] Message-ID: <23247@sun.uucp> Date: Sun, 12-Jul-87 02:21:52 EDT Article-I.D.: sun.23247 Posted: Sun Jul 12 02:21:52 1987 Date-Received: Mon, 13-Jul-87 00:39:56 EDT References: <17310@amdcad.AMD.COM> <2159@emory.uucp> <43@ghsvax.UUCP> <795@nu3b2.UUCP> Sender: news@sun.uucp Lines: 46 > > > Many compilers will materialize the (returned old value) of i++ even > > >when nobody wants it, but will do better with ++i. > > > > Ye gads! what braindamaged piece of software are you using?? - I've worked > > Pardon my foolish inquiry... isnt i++ SUPPOSED to return the old > value of i AND THEN increment it's stored value. No, it's supposed to evaluate to the old value of "i", but not necessarily "return" it. If that value is merely going to be thrown away - remember, lots of times you just want to increment "i", without using its value, so you write i++; or ++i; as statements by themselves - a compiler shouldn't produce code that wastes resources by materializing that value anywhere. I.e., if i++; as a statement by itself generates something like: move i,r0 add #1,i then the compiler that generated that is stupid. That statement should compile to add #1,i just as ++i; should. ("Compiler" here includes all passes; for instance, PCC tends to produce sloppy code in some cases because 1) it's a lot more work for it to do it right and 2) it knows that the peephole optimizer can clean up after it more easily than it can generate the proper code.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com