<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Prefer prefix operators over postfix</title>
	<atom:link href="http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/feed/" rel="self" type="application/rss+xml" />
	<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/</link>
	<description>Software, the Internet and you.</description>
	<lastBuildDate>Sat, 19 May 2012 09:06:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Mark C</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#comment-139691</link>
		<dc:creator>Mark C</dc:creator>
		<pubDate>Thu, 10 Nov 2011 20:50:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-139691</guid>
		<description>&quot;When you write postfix, you are communicating that
you need the old value after the increment.&quot;

100% baloney, unless you also consider that when you write prefix, you are &quot;communicating that you need the NEW value BEFORE the increment.&quot;</description>
		<content:encoded><![CDATA[<p>&#8220;When you write postfix, you are communicating that<br />
you need the old value after the increment.&#8221;</p>
<p>100% baloney, unless you also consider that when you write prefix, you are &#8220;communicating that you need the NEW value BEFORE the increment.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rasika</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#comment-132889</link>
		<dc:creator>rasika</dc:creator>
		<pubDate>Wed, 27 Jul 2011 06:01:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-132889</guid>
		<description>Explaination in well manner...</description>
		<content:encoded><![CDATA[<p>Explaination in well manner&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bennett</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#comment-113503</link>
		<dc:creator>Bennett</dc:creator>
		<pubDate>Fri, 22 Oct 2010 09:01:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-113503</guid>
		<description>@saint, that&#039;s your optimising compiler at work.</description>
		<content:encoded><![CDATA[<p>@saint, that&#8217;s your optimising compiler at work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: G.U. "saint" Lauri</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#comment-113435</link>
		<dc:creator>G.U. "saint" Lauri</dc:creator>
		<pubDate>Thu, 21 Oct 2010 17:07:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-113435</guid>
		<description>I wrote the same loop twice, the index is used for output and computation. In one loop I used the prefix operator, in the other the suffix... Who can say who is who ?


	.p2align 4,,7
	.p2align 3
.L2:
	movl	%ebx, 8(%esp)
	addl	$1, %ebx
	movl	$.LC1, 4(%esp)
	movl	$1, (%esp)
	call	__printf_chk
	cmpl	$10, %ebx
	jne	.L2

	.p2align 4,,7
	.p2align 3
.L3:
	movl	%ebx, 8(%esp)
	addl	$1, %ebx
	movl	$.LC1, 4(%esp)
	movl	$1, (%esp)
	call	__printf_chk
	cmpl	$10, %ebx
	jne	.L3</description>
		<content:encoded><![CDATA[<p>I wrote the same loop twice, the index is used for output and computation. In one loop I used the prefix operator, in the other the suffix&#8230; Who can say who is who ?</p>
<p>	.p2align 4,,7<br />
	.p2align 3<br />
.L2:<br />
	movl	%ebx, 8(%esp)<br />
	addl	$1, %ebx<br />
	movl	$.LC1, 4(%esp)<br />
	movl	$1, (%esp)<br />
	call	__printf_chk<br />
	cmpl	$10, %ebx<br />
	jne	.L2</p>
<p>	.p2align 4,,7<br />
	.p2align 3<br />
.L3:<br />
	movl	%ebx, 8(%esp)<br />
	addl	$1, %ebx<br />
	movl	$.LC1, 4(%esp)<br />
	movl	$1, (%esp)<br />
	call	__printf_chk<br />
	cmpl	$10, %ebx<br />
	jne	.L3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Chun</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#comment-108123</link>
		<dc:creator>Michael Chun</dc:creator>
		<pubDate>Sun, 23 May 2010 11:00:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-108123</guid>
		<description>Good stuff! Very well explained</description>
		<content:encoded><![CDATA[<p>Good stuff! Very well explained</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Math</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#comment-76135</link>
		<dc:creator>Math</dc:creator>
		<pubDate>Thu, 21 Aug 2008 15:54:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.thunderguy.com/plusplus/20050421/prefer-prefix-operators-over-postfix/#comment-76135</guid>
		<description>Man... what a bummer. I mostly like the postfix operator for its aesthetics in code rather than its &quot;save the old value&quot; functionality, though I do use that occasionally too. I wish I had known the efficiency stuff in this article before I started running rampant with postfix with almost all my code. Now since I&#039;m anal retentive, whenever I see i++, for example, I have to switch it to ++i.</description>
		<content:encoded><![CDATA[<p>Man&#8230; what a bummer. I mostly like the postfix operator for its aesthetics in code rather than its &#8220;save the old value&#8221; functionality, though I do use that occasionally too. I wish I had known the efficiency stuff in this article before I started running rampant with postfix with almost all my code. Now since I&#8217;m anal retentive, whenever I see i++, for example, I have to switch it to ++i.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ford prefix</title>
		<link>http://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#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&#039;t need the value, why in the world wold you write it that way?  If you don&#039;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 &#8211; 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://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#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&#039;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://thunderguy.com/semicolon/2002/08/13/prefer-prefix-operators-over-postfix/comment-page-1/#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&#039;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&#039;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>

