<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Interruption with IF</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/14866/interruption-with-if</link><description> I&amp;#39;m trying trying to program a square signal frequency to simulate the signal obtained in 
the sensor of the rpm of an engine (in the flywheel). This frequency is generated in a 
timer interruption. If I don&amp;#39;t take into consideration the two missing</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Interruption with IF</title><link>https://community.arm.com/thread/84285?ContentTypeID=1</link><pubDate>Fri, 28 Jun 2002 01:12:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:51339e43-82a8-43b0-954c-379fb26815c8</guid><dc:creator>Vaclav Korecek</dc:creator><description>&lt;p&gt;Sorry for my late reply. I am very busy, but I&amp;#39;d like to do reply for Jon&amp;#39;s contribution.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;quot;counter=counter++;&lt;br /&gt;
&lt;br /&gt;
is evaluated as follows:&lt;br /&gt;
&lt;br /&gt;
1. Obtain the value of counter.&lt;br /&gt;
2. Increment the value of counter.&lt;br /&gt;
3. Assign the value obtained in step 1 to &lt;br /&gt;
counter. &lt;br /&gt;
...&lt;br /&gt;
It is NOT a bug. It is how the C Language works.&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Jon,&lt;br /&gt;
It&amp;#39;s very thin ice you walking about in this case I think.&lt;br /&gt;
It&amp;#39;s right you wrote about r-value and l-value evaluation but why is made increment for the  &lt;b&gt;&amp;quot;counter=counter++;&amp;quot;&lt;/b&gt; statement in C51 V7.0 for all optimize levels?&lt;br /&gt;
&lt;br /&gt;
There are two variants of explanation by my opinion:&lt;br /&gt;
A. The &amp;quot;++&amp;quot; operator in &lt;b&gt;&amp;quot;counter++;&amp;quot;&lt;/b&gt; statement is postfix operator which means use variable and then increment.&lt;br /&gt;
&lt;pre&gt;
 1. Obtain the value of counter. 
 2. Assign the value obtained in step 1 to counter.
 3. Increment the value of counter.
&lt;/pre&gt; &lt;br /&gt;
B. Statement &lt;b&gt;&amp;quot;counter++;&amp;quot;&lt;/b&gt; is same as &lt;b&gt;&amp;quot;counter=counter+1;&amp;quot;&lt;/b&gt; or &lt;b&gt;&amp;quot;counter+=1;&amp;quot;&lt;/b&gt;. If I use it instead of original statement:&lt;br /&gt;
&lt;pre&gt;
  counter=counter++;  // original
  counter=(counter+=1);
&lt;/pre&gt;
Both statements  are optimized and evaluated in C51 V7.0 as increment while C51 V5.50 don&amp;#39;t evaluate them and optimize out both above mentioned statements.&lt;br /&gt;
&lt;br /&gt;
My question is:&lt;br /&gt;
What do you think about V7.0 and V5.50a compiler version differnces? &lt;br /&gt;
Is there some other explanation for V7.0 operation and what is right?&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
Vaclav&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption with IF</title><link>https://community.arm.com/thread/54482?ContentTypeID=1</link><pubDate>Sat, 22 Jun 2002 17:20:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:497f22fa-9eb0-4d04-87cc-4d37643ba722</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;&lt;i&gt;I just did a quick experiment with my Keil C version 6.14. The following statement:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	counter=counter++;&lt;br /&gt;
&lt;br /&gt;
was optimised out!&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
In the C Programming Language, a C compiler is supposed to evaluate everything on the RIGHT HAND SIDE of an assignment BEFORE it changes the thing on the LEFT HAND SIDE.&lt;br /&gt;
&lt;br /&gt;
So, with that in mind,&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
counter=counter++;
&lt;/pre&gt;
&lt;br /&gt;
is evaluated as follows:&lt;br /&gt;
&lt;br /&gt;
1. Obtain the value of counter.&lt;br /&gt;
2. Increment the value of counter.&lt;br /&gt;
3. Assign the value obtained in step 1 to counter.&lt;br /&gt;
&lt;br /&gt;
In effect, this statement does nothing.  So, the compiler optimized it out.  It is NOT a bug.  It is how the C Language works.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption with IF</title><link>https://community.arm.com/thread/38879?ContentTypeID=1</link><pubDate>Fri, 21 Jun 2002 07:07:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8a1b990b-f643-4f35-b825-5f9f7153c3cb</guid><dc:creator>Jorge Cases</dc:creator><description>&lt;p&gt;Thank&amp;#39;s a lot guys.&lt;br /&gt;
&lt;br /&gt;
You got the right answer. Now it&amp;#39;s working&lt;br /&gt;
&lt;br /&gt;
Jorge Cases&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption with IF</title><link>https://community.arm.com/thread/54481?ContentTypeID=1</link><pubDate>Fri, 21 Jun 2002 06:21:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:36ec0bb3-3a56-47d5-a80a-cc0bb91b1f2b</guid><dc:creator>Vaclav Korecek</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;counter=counter++;&amp;quot;&lt;/i&gt;&lt;br /&gt;
Under Keil C51 5.50 this statement don&amp;#39;t work&lt;br /&gt;
but under Keil C51 V7.0 seems it works OK.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  
    counter++; 
is a better &amp;#39;C&amp;#39; notation then    
    counter=counter++;
It looks unnatural. 
&lt;/pre&gt;
Vaclav&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption with IF</title><link>https://community.arm.com/thread/38868?ContentTypeID=1</link><pubDate>Fri, 21 Jun 2002 05:49:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e4a640d4-3b23-4078-a6ff-b0970e6dac6d</guid><dc:creator>Graham Cole</dc:creator><description>&lt;p&gt;I just did a quick experiment with my Keil C version 6.14. The following statement:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
	counter=counter++;
&lt;/pre&gt;
was optimised out! &lt;br /&gt;
&lt;br /&gt;
This is not a very conventional C statement, but it looks as if it should be legal. So, this looks like a compiler bug to me! It might be interesting to try compiling with lower levels of optimisation.&lt;br /&gt;
&lt;br /&gt;
With counter stuck at 0, I don&amp;#39;t think your code will be doing anything.&lt;br /&gt;
&lt;br /&gt;
Try:&lt;br /&gt;
&lt;pre&gt;
	counter++;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>