Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: what's wrong with this switch statement...

  1. #1
    digerati is offline Newbie
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Question what's wrong with this switch statement...

    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.
    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);
    				}
    Thanking you.
    Last edited by WingedPanther; 09-30-2008 at 09:29 AM. Reason: add code tags

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: what's wrong with this switch statement...

    Without seeing the definitions of your variables, it is very hard to help you out.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    digerati is offline Newbie
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Re: what's wrong with this switch statement...

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

  5. #4
    digerati is offline Newbie
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Re: what's wrong with this switch statement...

    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.

  6. #5
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: what's wrong with this switch statement...

    not sure.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  7. #6
    LogicKills's Avatar
    LogicKills is offline Programmer
    Join Date
    May 2008
    Location
    US
    Posts
    138
    Rep Power
    16

    Re: what's wrong with this switch statement...

    Why are you declaring your macros in your switch statements?
    http://logickills.org
    Science - Math - Hacking - Tech

  8. #7
    digerati is offline Newbie
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Re: what's wrong with this switch statement...

    i have a function which prints depending on the macros defined at that point of time

  9. #8
    Join Date
    Jul 2008
    Location
    Somewhere that is shorter to write than "In the gloomy shadows of my personal namespace"
    Posts
    10,725
    Blog Entries
    2
    Rep Power
    90

    Re: what's wrong with this switch statement...

    Can you achieve this that way?
    Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  10. #9
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: what's wrong with this switch statement...

    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  11. #10
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: what's wrong with this switch statement...

    You'll have to create an int variable and use the bits as flags.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Switch Statement
    By docmonkey in forum PHP Development
    Replies: 4
    Last Post: 06-17-2011, 03:46 PM
  2. Declaring an array and using within switch statement
    By thintheherd in forum C and C++
    Replies: 3
    Last Post: 06-02-2010, 03:12 AM
  3. Switch Statement
    By ahmed in forum C and C++
    Replies: 3
    Last Post: 11-07-2008, 02:57 PM
  4. Replies: 3
    Last Post: 10-18-2008, 10:05 AM
  5. Switch statement in string returning method...
    By ozyabm in forum C and C++
    Replies: 3
    Last Post: 07-06-2008, 12:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts