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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/19/03 09:42
Read: times


 
#58997 - RE: static
Responding to: ???'s previous message
"I believed by declaring a variable as static, it serves two purposes..
1. It get initialized to a default value.
2. Its value persists between function calls."


You missed one - and it's the important one in this case:

3. It restricts identifiers defined outside any function to File Scope

By default, identifiers defined outside any function are Global.
As I said before, If your header file is defining data and/or code, and you include it in multiple .c source files, then you will get multiple definition errors from the Linker!!

As Donald has explained, your variables are no longer Global - instead, each "module" has its own private copy of each one!
This is unlikely to be what you want?

Note that none of this is specific to the 8051 - this is all bog-standard ANSI 'C' stuff.

"Now, a better guide to Stephene Reys C-Standards would be nice."

Actually, a good read of K&R is what's needed here - particularly the bits on Scope and Linkage

List of 20 messages in thread
TopicAuthorDate
Problem when I split Source Code            01/01/70 00:00      
   RE: Problem when I split Source Code            01/01/70 00:00      
      Downloading the File...            01/01/70 00:00      
         RE: Downloading the File...            01/01/70 00:00      
         aaaaaaaaaaarrrrrrrrrgggggggggghhhhhhhhhh            01/01/70 00:00      
            RE: aaaaaaaaaaarrrrrrrrrgggggggggghhhhhhhhhh            01/01/70 00:00      
               RE: aaaaaaaaaaarrrrrrrrrgggggggggghhhhhhhhhh            01/01/70 00:00      
   RE: Problem when I split Source Code            01/01/70 00:00      
      RE: Problem when I split Source Code            01/01/70 00:00      
   RE: Problem when I split Source Code            01/01/70 00:00      
   RE: Header Files            01/01/70 00:00      
      RE to SUSHIL and THE SOLUTION            01/01/70 00:00      
         RE: RE to SUSHIL and THE SOLUTION            01/01/70 00:00      
            RE: RE to SUSHIL and THE SOLUTION            01/01/70 00:00      
         RE: static            01/01/70 00:00      
            Thanks Donald and Andy            01/01/70 00:00      
               Important Lesson            01/01/70 00:00      
            Structure Still not working !!            01/01/70 00:00      
               RE: Structure Still not working !!            01/01/70 00:00      
                  Eureka.. :)            01/01/70 00:00      

Back to Subject List