<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Prefer prefix operators over postfix</title>
	<atom:link href="http://www.thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/</link>
	<description>Software, the Internet and you.</description>
	<pubDate>Sat, 05 Jul 2008 12:37:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: ford prefix</title>
		<link>http://www.thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/#comment-65021</link>
		<dc:creator>ford prefix</dc:creator>
		<pubDate>Thu, 24 Apr 2008 22:54:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-65021</guid>
		<description>The real reason to use prefix rather than postfix is because when you have a choice,
you should write exactly what you mean.  When
you write postfix, you are communicating that
you need the old value after the increment.  If you don't need the value, why in the world wold you write it that way?  If you don't need the old value, use prefix.

Would you leave statements such as this:

{
   int f = 0;
   // ...
   f + 1;
   f - 1;
   // use f for real purpose
}

laying around in your code?

Say what you mean, mean what you say.</description>
		<content:encoded><![CDATA[<p>The real reason to use prefix rather than postfix is because when you have a choice,<br />
you should write exactly what you mean.  When<br />
you write postfix, you are communicating that<br />
you need the old value after the increment.  If you don&#8217;t need the value, why in the world wold you write it that way?  If you don&#8217;t need the old value, use prefix.</p>
<p>Would you leave statements such as this:</p>
<p>{<br />
   int f = 0;<br />
   // &#8230;<br />
   f + 1;<br />
   f - 1;<br />
   // use f for real purpose<br />
}</p>
<p>laying around in your code?</p>
<p>Say what you mean, mean what you say.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bennett</title>
		<link>http://www.thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/#comment-33584</link>
		<dc:creator>Bennett</dc:creator>
		<pubDate>Fri, 29 Jun 2007 04:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-33584</guid>
		<description>Good stuff, Sam. I just &lt;em&gt;talk&lt;/em&gt; about what compilers &lt;em&gt;might&lt;/em&gt; do, but you go the extra mile and find out. Nice to know that gcc optimises simple loops. But I also said:
&lt;blockquote&gt;
In this case, of course, the compiler will probably realize that the value of the expression is not used, and can therefore avoid the copy.
...
Even if i is an integral type today, somebody might change it tomorrow to be some relatively heavyweight class type like an iterator: suddenly, you get a new object created and destroyed every time through the loop.
&lt;/blockquote&gt;

And don't forget about visibility and consistency too, which in most cases are more important than efficiency anyway.</description>
		<content:encoded><![CDATA[<p>Good stuff, Sam. I just <em>talk</em> about what compilers <em>might</em> do, but you go the extra mile and find out. Nice to know that gcc optimises simple loops. But I also said:</p>
<blockquote><p>
In this case, of course, the compiler will probably realize that the value of the expression is not used, and can therefore avoid the copy.<br />
&#8230;<br />
Even if i is an integral type today, somebody might change it tomorrow to be some relatively heavyweight class type like an iterator: suddenly, you get a new object created and destroyed every time through the loop.
</p></blockquote>
<p>And don&#8217;t forget about visibility and consistency too, which in most cases are more important than efficiency anyway.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Danielson</title>
		<link>http://www.thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/#comment-33550</link>
		<dc:creator>Sam Danielson</dc:creator>
		<pubDate>Thu, 28 Jun 2007 11:30:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-33550</guid>
		<description>Here's the objdump -d a.out for a postfix loop with a simple body. I compiled this with with gcc 4.1.2, with the -ggdb option.

The machine isn't storing a copy of i, it just puts the i++ after the body of the loop.

	for (i = 0; i 
 804835e:	8b 45 f4             	mov    0xfffffff4(%ebp),%eax
 8048361:	89 45 f8             	mov    %eax,0xfffffff8(%ebp)
 8048364:	83 45 f4 01          	addl   $0x1,0xfffffff4(%ebp)
 8048368:	83 7d f4 09          	cmpl   $0x9,0xfffffff4(%ebp)
 804836c:	7e f0                	jle    804835e </description>
		<content:encoded><![CDATA[<p>Here&#8217;s the objdump -d a.out for a postfix loop with a simple body. I compiled this with with gcc 4.1.2, with the -ggdb option.</p>
<p>The machine isn&#8217;t storing a copy of i, it just puts the i++ after the body of the loop.</p>
<p>	for (i = 0; i<br />
 804835e:	8b 45 f4             	mov    0xfffffff4(%ebp),%eax<br />
 8048361:	89 45 f8             	mov    %eax,0xfffffff8(%ebp)<br />
 8048364:	83 45 f4 01          	addl   $0&#215;1,0xfffffff4(%ebp)<br />
 8048368:	83 7d f4 09          	cmpl   $0&#215;9,0xfffffff4(%ebp)<br />
 804836c:	7e f0                	jle    804835e</p>
]]></content:encoded>
	</item>
</channel>
</rss>
