View Single Post
  #5   Spotlight this post!  
Unread 08-02-2004, 15:38
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,801
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
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;
volitile tells the compiler not to assume the memory location of the variable retains it's value. It will check that the variable has the correct value whenever your code uses it.
static tells the compiler to always retain the variable's value.

You'll want to use static quite often.
In the following example, divisor will increase in value every time My_stuff() is called, but x will always start fresh as 0 each time and increase to 1, before being lost when you exit the routine:
Code:
void My_stuff()
{
  static unsigned int divisor =0;
  unsigned int x=0;

  x++;
  divisor++;
}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle