View Single Post
  #6   Spotlight this post!  
Unread 04-29-2005, 03:48 PM
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0395 (2Train Robotics)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Long Island City, NY
Posts: 1,434
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: #define and #ifdef/endif

Quote:
Originally Posted by Dave Scheck
...Chris posted while I was typing this....

Short answer is that #define and #if switches are processed before the compiler ever sees the code. Therefore you can't do what you are trying to do. You'd be better off storing the program number into a variable and deciding what to do based on that
Code:
enum
{
PROG_DO_NOTHING = 0,
PROG1,
PROG2
};
static int g_prog_num = PROG_DO_NOTHING;
....
if(rc_dig_in01==1)
{
g_prog_num = PROG1;
}
else if(rc_dig_in02==1)
{
g_prog_num = PROG2;
}
 
switch(g_prog_num)
{
case PROG1:
printf("Hello, world.");
break;
case PROG2:
printf("FIRST Robotics");
break;
default:
printf("DO NOTHING");
break;
}
Thank you very much for all the replies.

Dave, I am unfamiliar with the 'enum' command, what does it do? Assign values to the identities inside, ascending from the value assigned to the first identity?

Again, thank you very much,