View Single Post
  #2   Spotlight this post!  
Unread 01-03-2005, 23:29
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Static Variables

Quote:
Originally Posted by amateurrobotguy
If I want to define a variable inside of a function and want it to be available to all functions in the .c file, will static do it?
No, not as you listed it. If you declare a variable inside a function (static or not), it is only available inside that function. The difference is that a static variable declared inside a function will retain its value between calls to that function. So it acts like a global variable but it can only be seen by that function.

If you need to access a variable from many functions you can either make it a global variable or pass it around as part of the function calls.