|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#9
|
|||
|
|||
|
Re: Why Static Variables?
Wow, I just got pwnt. Very nice post.
Can you link us to more information on overlay variables? I am unfamiliar with them. The optimization I was referring to was the distinction between using the stack and not using the stack. Usually when one of my students proposed using a static variable, this was the purpose. I think the issue was the difference between: Code:
static int i; i=0; Code:
static int i=0; Sorry for any confusion. I've actually fixed more C code than I've written myself, so I'm more familiar with bad strategies than good ones. In general, I'd force them to explain exactly why they want to use these static variables. A counter internal to a function? Great. An ill-informed attempt at scope-narrowing? Bad. A well informed attempt at scope-narrowing? Good. Writing a function and assuming it will always operate on a single set of data? NIGHTMARE. What happens if you suddenly grow another wheel/senesor/anything? I do love "as narrow as possible" scoping, but I prefer placing variables with their buddies. This is a paraphrased version of why I demand buddy variables share scope: Code:
int softenMotor(int intended_value){
static int old_value=127;
int new_value = (old_value+intended_value);
old_value=new_value;
return new_value;
}
I know I am being overly cranky. I know that no body would actually do that (more than twice). I am simply speaking as one who has burned himself with premature optimization time and time again. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Static Cling?? | orelinde | Electrical | 17 | 27-02-2006 17:33 |
| Static Variables | amateurrobotguy | Programming | 8 | 04-03-2005 00:40 |
| Static Electricity | JeffO | Championship Event | 5 | 19-04-2004 11:04 |
| Static on the HDPE | Al Skierkiewicz | Technical Discussion | 60 | 12-03-2003 17:52 |
| Static Electricity | archiver | 2001 | 12 | 24-06-2002 00:34 |