Will the printf’s change when i flip either of the switches? Basically, my question is if code between #ifdef/#endif is loaded onto the robot, and whether or not variables can be defined on the fly, based on switch input.
That should not work. #define statements, #ifdef, #endif, and anything starting with the # symbol are preprocessor directives. Therefore, they are not runtime code - they just tell the compiler how to compile. They do nothing at run time.
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
The enum represents an “enumeration” or “enumerated list”. Your interpretation is correct. It creates a list of constants to be used later in your code. The constants are numbered by adding one to the previous value. You can also change the numbering scheme whenever you want to by doing the following
One of the benefits is that you don’t have to define the values for the constants as they will autoincrement. If used properly, you won’t have to worry about accidentally reusing numbers. You will also be able to renumber the constants simply by rearranging them in the enum structure. Here’s an example…
Say that you have 3 steps to a process defined as #defines
While there is nothing wrong with this, your constants don’t reflect the fact that STEP_D occurs before STEP_C.
If your original code was written with enums
STEP_A = 1,
You could easilly add STEP_D and have the step order make sense
STEP_A = 1,
Unlike a #define, these constants will reside in the memory space of your program, as opposed to being substituded in pre-compilation. This may be a downside if you have limited memory or speed.
In the context that I used in my original response, #defines would have been just fine, I just chose to go with the enum because I wasn’t too concerned with the values that the constants took on…I was more interested in having unique constants.
Thanks Dave. The function robot_command() is in robot.c. That is the function that is called from user_routines_fast. Due to that fact, I am putting check_switch_box() in robot.c, so since current_command is a global declared in robot.c, check_switch_box should be able to see it, correct?