<?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>Volatile keyword</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/30067/volatile-keyword</link><description> 
IU have a variable which can be chyanged outside the interrupt but
inside the ISR it is only read. Its value don&amp;#39;t change in it. Should
it be volatile. 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/128034?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 05:53:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1f312336-c26d-4942-96a5-7e0ff457bc25</guid><dc:creator>Scott Douglass</dc:creator><description>&lt;p&gt;&lt;p&gt;
volatile can also be useful on auto variables in functions that
call setjmp&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/140520?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 05:48:47 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e6d1b1e4-0af6-4106-ab90-fa5c6b194dcb</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Note that the function that gets a pointer to a variable will not
be able to generate any code based on any &amp;quot;auto&amp;quot; optimization rules.
From a code perspective, it will just be a pointer to memory - and
the majority of processors don&amp;#39;t have any special, magic, memory
reserved for &amp;quot;auto&amp;quot; variables.&lt;/p&gt;

&lt;p&gt;
But the compilers do have sets of optimization rules that looks
different, depending on what is known about a variable at the point
of access. So the optimizers have different rule sets if they see a
variable as auto, or global or indirectly accessed.&lt;/p&gt;

&lt;p&gt;
Unless the function call is inlined, the variable will no longer
be seen as an auto variable - but the pointer to it will be - when
the execution enters the receiving function.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/136965?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 05:21:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9c1fe701-af66-4366-8835-70ba04fd419c</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
No, I don&amp;#39;t think there&amp;#39;s any question about that.&lt;/p&gt;

&lt;p&gt;
Whether a variable is automatic or not doesn&amp;#39;t depend on how you
use - or abuse - it.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/131208?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 02:30:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e5e1b528-75da-46ae-b2d5-95d2ffd3801a</guid><dc:creator>Gaseous Trousers</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;But the question is if it should be seen as an &amp;quot;auto&amp;quot; variable
when people accesses it using pointers&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Yes.&lt;/p&gt;

&lt;p&gt;
You disappoint me. I have nothing further to say on the matter.
Goodbye.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/128040?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 02:18:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5b8e5070-15f4-46ab-8239-0393f450ba62</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Well, volatile isn&amp;#39;t needed for auto variables. But a developer
can manage to create aliasing to that variable by taking the address
of it. But the question is if it should be seen as an &amp;quot;auto&amp;quot; variable
when people accesses it using pointers. Aliasing, by the way, is one
of the better known methods to create truly broken code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/117193?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 01:53:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:da4085ad-d7e5-4b36-aed2-152047b69828</guid><dc:creator>Gaseous Trousers</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;volatile is never needed for auto variables.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Errrm. &lt;i&gt;never&lt;/i&gt; is a little too strong. It is possible for the
address of that variable to be passed to something that is processed
by an ISR.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/106883?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2013 01:28:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f6b1f594-fd52-4552-8056-5fd391c64091</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
volatile is never needed for auto variables.&lt;/p&gt;

&lt;p&gt;
They have a lifetime corresponding to the lifetime of the stack
frame for that function call.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/81002?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2013 21:33:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:503b89e0-7f55-41ed-b9c3-ef5fe045bb76</guid><dc:creator>Aamir Ali</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks for answer.&lt;/p&gt;

&lt;p&gt;
One more similar question:&lt;/p&gt;

&lt;p&gt;
Suppose i have a variable which is only accessed inside ISR. So I
think there no need to declare it volatile. Right???&lt;/p&gt;

&lt;p&gt;
Also suppose if the code of ISR, I write it in function &amp;amp;
declare the function with following statement:&lt;br /&gt;
Now is there need of declaring a as volatile.&lt;/p&gt;

&lt;pre&gt;
void __isr(void)
{
    code_of_isr();
}


__attribute__( ( always_inline ) ) __STATIC_INLINE code_of_isr(void)
{
   int a;             /* a is only used here. Not outside in main or anywhere  */
   a= 10;
   //////////////////next code parts

}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Volatile keyword</title><link>https://community.arm.com/thread/68110?ContentTypeID=1</link><pubDate>Wed, 20 Feb 2013 05:34:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a325809d-236a-4951-843d-fb8d363a1d81</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
The ISR always needs to read the variable - there are no cache
somewhere for the processor to keep the value since previous
interrupt.&lt;/p&gt;

&lt;p&gt;
So you don&amp;#39;t need &amp;quot;volatile&amp;quot; to make sure the ISR will pick up the
current value. Unless you have nested interrupts that both uses the
variable and the higher-prio interrupt may change the value.&lt;/p&gt;

&lt;p&gt;
You do need &amp;quot;volatile&amp;quot; if the ISR changes a variable, to make sure
the main loop will pick up the changes.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>