View Single Post
  #4   Spotlight this post!  
Unread 08-02-2004, 15:39
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Re: volatile keyword

Quote:
Originally Posted by mightywombat
as an addition to my last post, what does the keyword static mean as well? as in:
static unsigned int divisor =0;

Static means that only one copy is used of the variable in all instances of the function. For example,

void foo(){
static int count = 0;
count++;
printf("%d", count);
}

int main(int argc, char *argv[]){
while(true)
foo();
}

would print out 123456789101112, etc whereas

void foo(){
int count = 0;
count++;
printf("%d", count);
}

would just print out 1 every time since the function can't keep track of things between calls.


As for volatile, it basically tells the compiler that it's possible that something other than the program itself could change the value of this variable, so don't try to do any crazy optimization stuff. Chances are that you won't really need it much (if ever), but it's good to know its there just in case.

-Rob
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php