Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/20/04 06:40
Read: times


 
#83484 - re: volatile
Responding to: ???'s previous message
In situatuion like above one, I use 'i' nowhere else in function otehr than mentioned. Do I need to use "volatile" keyword for 'i'.


No. The "volatile" keyword is a hint to the compiler that something other than the program may change the value of the variable, and the compiler should generate code that always goes out and reads the latest value of that variable rather than using a value cached in a register or something.

A good example would be if you had a memory-mapped "mailbox register." This is a register that you can read and write but also some other external hardware may read and write it independent of the micro.

Since the 8052 doesn't have any real MMU hardware (it doesn't have a cache), then I think that this keyword doesn't actually do all that much for you, especially regarding automatic variables. However, as Andy Neil points out, declaring a variable to be volatile forces the compiler to assume that something else (whatever that may be) may use it and so it (and code that manipulates it) won't be optimized away.

--a

List of 22 messages in thread
TopicAuthorDate
Help LCD--89C51 using KEIL            01/01/70 00:00      
   RE            01/01/70 00:00      
   Keil?            01/01/70 00:00      
      Keil App Notes            01/01/70 00:00      
   Assembler programmer learning C?            01/01/70 00:00      
   So what happened to the USB, then?            01/01/70 00:00      
   The wanted code...            01/01/70 00:00      
      code            01/01/70 00:00      
         Tips and Tricks.....Andy            01/01/70 00:00      
            volatile.            01/01/70 00:00      
               Not so volatile ?            01/01/70 00:00      
                  optimiser            01/01/70 00:00      
                     Volatile warning?            01/01/70 00:00      
                        not here            01/01/70 00:00      
                        re: volatile            01/01/70 00:00      
                           volatile            01/01/70 00:00      
      Another comment - symbolic names            01/01/70 00:00      
   c code for lcd            01/01/70 00:00      
      code            01/01/70 00:00      
         symbolic Port names            01/01/70 00:00      
   There's Gratitude for you! :-(            01/01/70 00:00      
   A better method in C            01/01/70 00:00      

Back to Subject List