View Single Post
  #3   Spotlight this post!  
Unread 08-02-2006, 17:28
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Defining file name?

Since the question was already answered, here's more info.

You can do other fun things with preprocessor stuff like that.

Example: What if you wanted your code to do something while you were debugging, and something else in your 'production' or complete competition code?

Code:
#define DEBUG

int shoot()
{
#ifdef DEBUG
  printf("shooting!")
#endif
  shootTheBall()
}
Basically, the compiler comes through and evaluates the if statement. If it is true, then it will include what is between #if and #endif. Otherwise, it is as if that code is not even there. It's an improvement over using actual code to block out bits, because it doesn't take any of your memory on the robot, and doesn't take any run-time computation to determine whether or not to run printf("shooting!").

So when you're debugging, you just #define DEBUG. When you want your final code to be faster/smaller, just remove the #define DEBUG line, and all your debug-related things will be removed.