Thread: " Missing ';' before 'type' " ?

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    " Missing ';' before 'type' " ?

    Code:
                    switch(LOWORD(wParam))
    		{
    			case ID_FILE_EXIT:
    				PostMessage(mainww, WM_CLOSE, 0, 0);
    			break;
    			
    			case ID_HELP_ABOUT:
    /*error here */			int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ABOUT), mainww, AboutDlgProc);
    			break;
    		}
    what's wrong? I have all my semicolons!

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    change
    Code:
    int ret =
    to
    Code:
    ret =

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Is that the only error that you're getting?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    you cannot declare variables in a switch!

    to get around this limitation you can use blocking,

    Code:
    case ID_HELP_about :
    {
        int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ABOUT), mainww, AboutDlgProc);
    }
    break;
    Last edited by no-one; 10-01-2003 at 05:25 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    That code stills has you declaring a variable inside the switch no-one

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    I'm getting off the original question here a little, but...

    >you cannot declare variables in a switch!

    Yes you can. But the usefulness may be questionable. Here is a hideous example (for entertainment mostly).
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       int i;
       for ( i = 0; i < 5; ++i )
       {
          switch ( i )
          {
             int i = 42; /* 'i' is declared, but not initialized,
                            it also hides the outer 'i' */
          case 0: i = printf("Hello\n"); goto hell;
          case 1: i = printf("everybody!\n"); goto hell;
          default: hell: printf("i = %d\n", i++);
          }
       }
       return 0;
    }
    
    /* my output
    Hello
    i = 6
    everybody!
    i = 11
    i = 12
    i = 13
    i = 14
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >That code stills has you declaring a variable inside the switch no-one

    note: that what i said was a method of "By-passing" this, by using the blocking functionality.

    >Yes you can. But the usefulness may be questionable. Here is a hideous example (for entertainment mostly).

    Well, to be honest i've actual never seen that one... and i'm not sure as to how legal that is... anyway both ways are technically loop-holes, ie abuses of the blocking operators, and both should be avoided, where possible.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM