Go to Post The robot competition is the most obvious, visible, and distilled-media-friendly part of the picture... We shouldn't be surprised that it's all that gets into the news coverage, when that coverage is managed by someone who isn't already well versed in what FIRST is trying to do. - Alan Anderson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Spotlight this post!  
Unread 25-01-2007, 02:23
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
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;
and
Code:
static int i=0;
I believe the first usage is where "overlay" is useful?

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;
}
Oh goodness, the left and right motors are suddenly bound together through old_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
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 23:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi