Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!mcvax!ukc!its63b!hwcs!hwee!hmc
From: hmc@hwee.UUCP (Hugh Conner)
Newsgroups: comp.lang.c
Subject: Re: Style [++i vs i++]
Message-ID: <259@hwee.UUCP>
Date: Tue, 14-Jul-87 04:54:11 EDT
Article-I.D.: hwee.259
Posted: Tue Jul 14 04:54:11 1987
Date-Received: Fri, 17-Jul-87 05:58:04 EDT
References: <17310@amdcad.AMD.COM> <246@hubcap.UUCP>
Reply-To: hmc@hwee (Hugh Conner)
Organization: Heriot-Watt University, Electrical Eng.
Lines: 30

In article <246@hubcap.UUCP> beede@hubcap.UUCP (Mike Beede) writes:
>in article <17310@amdcad.AMD.COM>, tim@amdcad.AMD.COM (Tim Olson) says:
>>
>> [ question: use ++i or i++ when only side-effect is desired ]
>> 
>There is no reason a compiler needs to generate code differently for i++; and
>++i; if that is the entire expression (and statement).
>

As I remember the original PDP-11 C compiler did treat the two cases
differently. This was because the PDP had an autoincrement addressing mode
of the form

	Op (Rn)+

which meant that register n was used as a pointer to a location and then
incremented. This made i++ more efficient that ++i since it could make use
of this mode. Similarly the autodecrement mode on the PDP took the form

	Op -(Rn)

thus making --i more efficient than i--.

This is probably no longer true of many (or all) systems, but it still
affects the way I tend to write programs.

-- 
+              "Who are all these people in my office anyway?"                +
+                                                                             +
+     Hugh M. Conner                                  hmc@ee.hw.ac.uk         +