View Single Post
  #10   Spotlight this post!  
Unread 25-01-2007, 02:40
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Why Static Variables?

Quote:
Originally Posted by EricVanWyk View Post
I do love "as narrow as possible" scoping, but I prefer placing variables with their buddies.
If variables are "buddies", then group them in a struct. If the data needs to persist, then make the instance of the struct static. Functions that work on the data can then just take a pointer to the structure as an argument so one function can handle both left and right wheel data, for instance.

Write file modules around functions that work on one structure type. This allows you to mimic some of the good organization that comes with using C++ classes in C. File scope static variables are equivalent to class static variables. Static functions are equivalent to protected or private C++ functions. Only expose the public interface to struct with the global functions. This keeps things pretty encapsulated. You can preface all the global functions with a name related to the structure they work on to minimize name clashes.