avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Affecting variables


From: Larry Barello
Subject: Re: [avr-gcc-list] Affecting variables
Date: Mon, 7 May 2001 20:38:22 -0700

You need to declare bTest as a "volatile".  The compiler has cached the
value of the variable in a register and referred to the register inside the
loop.  Declaring it volatile will tell the compiler that the variable might
change between loops and to re-load it each time.  Any shared static or
global variable that can be modified outside of the code flow (e.g.
multitasking or interrupts) needs to be declared volatile so the compiler
knows not to cache the value in a register.

Try using the -S compiler switch and generate the assembly code and look at
it.  You can learn a lot that way.

Question: could someone illuminate the difference between:

volatile char bTest;
char volatile bTest;

or are they the same?

Cheers!

----- Original Message -----
From: "Paulo Abreu" <address@hidden>
To: <address@hidden>
Sent: Monday, May 07, 2001 4:53 PM
Subject: [avr-gcc-list] Affecting variables


> I am doing something like this (unfortunately I forgot my .c file)
>
> char bTest;
>
> void init(void)
> {
>   bTest=0;
> }
>
> /* receive uart handler */
> SIGNAL(...)
> {
>   bTest=1;
> }
>
> int main(void)
> {
>
>   init();
>
>   while(1)
>   {
>     if(bTest == 1)
>     {
>       /* do something*/
>     }
>   }
> }
>
>
> what is happening is that bTest is not being affected, that is, bTest!=1,
> why?
>
> I am using the last version of avr-gcc for windows.
>
> Thanks in advance for your attention,
>
> Paulo Abreu
>
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]