On 24/10/12 15:34, mind entropy wrote:
> On Wed, Oct 24, 2012 at 3:58 PM, David Brown <da...@westcontrol.com> wrote:
>
>> On 24/10/2012 09:38, mind entropy wrote:
>>> On Wed, Oct 24, 2012 at 12:36 PM, Eric Decker <cire...@gmail.com>
>>> wrote:
>>>
>>>>
>>>>
>>>> On Tue, Oct 23, 2012 at 11:14 PM, mind entropy
>>>> <mindentr...@gmail.com>wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I was reading the mspgcc manual (
>>>>>
>>>>>
>> http://www.eecs.harvard.edu/~konrad/projects/motetrack/mspgcc-manual-20031127.pdf
>>>>>
>>>>>
>> )
>>>>> and on Pg 39 its written as
>>>>>
>>>>
>>>> I believe there is a more up to date version but I'm not usre where
>>>> it lives.  Perhaps Peter can point to it?
>>>>
>>>>
>>>>>
>>>>> "If you execute while ((long) a & 0x80000l); the program will
>>>>> hang, unless ’a’ is declared volatile. So, do it!"
>>>>>
>>>> With optimization a will be put into a register (actually two
>>>> registers since it is a long) and loaded once.
>>>>
>>>> If a is declared as a volatile, that tells the toolchain that a can
>>>> change out from underneath any assumptions made about contents.
>>>> This forces the compiler to reload a into a register each
>>>> iteration.
>>>>
>>>
>>> Its loaded once during the start of the iteration right?
>>> Theoretically if there is no change from outside is there a point in
>>> making it volatile?  i.e. if that loop block is the only thing in the
>>> loop?
>>>
>>
>> If "a" is not volatile, the compiler will generate code that is like this:
>>
>> long localCopyOfA = a;
>> if (localCopyOfA & 0x800001) {
>>          while (true) ;
>> }
>>
>> If that is what you meant to write, then it's fine to have "a"
>> non-volatile.  But I /really/ doubt that this is what you want.
>>
>> The loop is completely useless unless "a" is modified from outside in
>> some way - from an interrupt function (the typical case), via hardware
>> (maybe "a" is a register, or perhaps modified by DMA), from another RTOS
>> thread, or even via a debugger (such constructs can sometimes be useful
>> in testing and debugging).  In all these cases, you have to let the
>> compiler know that "a" may be modified externally - and you do that by
>> declaring it "volatile".
>>
>>
> Yes I realized it later. The code I have below would not need to have
> volatile right since
> the change is not made externally from an interrupt etc (Assuming that code
> is the only
> code in the program)
>
> unsigned long a = 0L;
> while(a < 10L) {
>     a++;
> }
>
>

I've had a look at the pdf you linked.  While a lot of the information 
there is useful, there is also a lot that is out of date - be careful 
about relying too much on the details here.

The "Tips and Tricks" chapter you mentioned contains some useful advice, 
but also a number of mangled or plain incorrect points.  Much of them 
could be summarised as "learn to write correct C".



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to