rror: expected ':' before numeric constant

Discussion in 'iOS Programming' started by wanting2learn, Oct 23, 2010.

  1. wanting2learn macrumors newbie

    Joined:
    Aug 19, 2010
    #1
    If I do this in my header file:

    Code:
    #define WM_USER 0x0400;
    const UINT MSGID_FIRST	= WM_USER + 1;
    
    I get the error:
    error: expected ':' before numeric constant


    Why is this and how can I solve it?


    Thanks
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    In this example, think of the C preprocessor as a mechanism for doing a kind of "search and replace" within the source file.

    What do you get when you simulate what the C preprocessor does by manually substituting the definition of WM_USER in that line of code?
     
  3. wanting2learn thread starter macrumors newbie

    Joined:
    Aug 19, 2010
    #3
    thanks

    if I do this:
    const UINT MSGID_FIRST = 0x0400 + 1;

    Then it does not give an error.
    So I'm thinking that its somethig to do with the #define not giving a type to WM_USER, so I tried:

    const UINT WM_USER = 0x0400;
    const UINT MSGID_FIRST = WM_USER + 1;

    But then it gave me the following error on the same line:
    error: initializer element is not constant

    So I'm out of ideas sorry,

    Thanks for your help.
     
  4. wanting2learn thread starter macrumors newbie

    Joined:
    Aug 19, 2010
    #4
    thanks

    Sorry my friend,
    it was the ';' at the end :eek:,

    how embarrassing lol

    Thanks again for your help
     
  5. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #5
    Don't be embarrassed -- it's an easy mistake to make :D

    Many programmers prefer to constants or enumerated values instead of #define's -- and in so doing improve the maintainability and debug-ability of their code.
     

Share This Page