How to fix "expected identifier or '(' before '{' token" errors?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Phacer
    New Member
    • Feb 2011
    • 3

    How to fix "expected identifier or '(' before '{' token" errors?

    When trying to compile I get this

    /main.c:30: error: expected identifier or '(' before '{' token
    ../main.c:31: error: expected identifier or '(' before 'if'
    make: *** [main.o] Error 1

    Code:
    SDL_SysWMinfo info;
    SDL_VERSION(&info.version);
    if ( SDL_GetWMInfo(&info) ) {
      Display *dpy = info.info.x11.display;
      Window win;
    These are the lines, line 30 and 31 are the second SDL one and the if (... one.

    I tried changing anythign around there, but it doesn`t
    seem to work. Any ideas?

    Thanks!
  • Jason Mortmer
    New Member
    • Feb 2011
    • 23

    #2
    You have to put a closing brace '}' at the end of the function.
    Last edited by Niheel; Feb 27 '11, 02:38 AM. Reason: Please stick to the question asked. You can always report bad questions.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      SDL_VERSION is a macro that, in your case, will expand to something like this:
      Code:
      {
          (&info.version)->major = SDL_MAJOR_VERSION;
          (&info.version)->minor = SDL_MINOR_VERSION;
          (&info.version)->patch = SDL_PATCHLEVEL;
      }
      I think both of the warnings are complaining about the curly braces generated by the macro. I don't see anything wrong here. Perhaps your version of the macro expands to something slightly different than this.

      Try the following as an experiment: change line 2 from
      Code:
      SDL_VERSION(&info.version);
      to
      Code:
      do SDL_VERSION(&info.version) while(0);
      My suggestion is a travesty -- please don't leave it like that even if the warnings go away.

      Which compiler are you using?

      Comment

      • Phacer
        New Member
        • Feb 2011
        • 3

        #4
        Well, somehow the error seems to have gone, and
        I don`t know why.
        I think it`s crazy, but restarting the pc made it go...?
        Anyway, now I get a new error..

        Code:
        cc1plus: warning: command line option "-std=c99" is valid for C/ObjC but not for C++
        In file included from ../main.c:20:
        ../common.h:105:19: error: SDL.h: No such file or directory
        In file included from ../common.h:245
        even tough I don't have c++ files, nor mentions on
        makefile or any of the project files...

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          The errors aren't gone -- this new problem is masking the old one.

          What compiler are you using?
          How are you invoking it?

          Comment

          • Phacer
            New Member
            • Feb 2011
            • 3

            #6
            In fact, I was making a silly mistake on my
            c sufixes on my makefile =)
            Thanks for everyone`s help!

            Comment

            Working...