Hello Coders,
I am trying to use this switch statement and it gives me an error, saying syntax error before token '=' in all the case statements except for the first and last case statement, all the variables have been defined fine.
Thanking you.Code:switch (op) { case 'l': LONG_MODE = TRUE; #define LONG_MODE break; case 'a': DISPLAY_ALL_FILES = TRUE; #define DISPLAY_ALL_FILES break; case 'C': COL_MODE = TRUE; LONG_MODE = FALSE; #define COL_MODE #undef LONG_MODE break; case 'd': DIR_MODE = TRUE; #define DIR_MODE break; case 'R': RECURS_MODE = TRUE; #define RECURS_MODE break; case 'S': SORT_MODE = TRUE; #define SORT_MODE break; default : print_help(2); }
Last edited by WingedPanther; 09-30-2008 at 09:29 AM. Reason: add code tags
Without seeing the definitions of your variables, it is very hard to help you out.
static bool DISPLAY_ALL_FILES = FALSE, DIR_MODE = FALSE, RECURS_MODE = FALSE, LONG_MODE = FALSE, COL_MODE = FALSE, SORT_MODE = FALSE;
These are my variables...
The problem was i was using the same names for both the #define and the variable name, but i am still confused on why it did not complain for the first and last case.
not sure.
Why are you declaring your macros in your switch statements?
http://logickills.org
Science - Math - Hacking - Tech
i have a function which prints depending on the macros defined at that point of time
Can you achieve this that way?
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
You do realize that ALL the macros end up being defined, don't you? The macros are defined by the preprocesser, not at execution time.
You'll have to create an int variable and use the bits as flags.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks