View Single Post
  #4   Spotlight this post!  
Unread 29-04-2005, 15:27
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: #define and #ifdef/endif

...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;
}