Flo
Flo

Reputation: 351

c error: case label does not reduce to an integer constant

This is the switch case concerned by the error:

switch(event.type)
        {
        case SDL_Quit:
            for (int i=0;i<NUMMENU;i++)
                SDL_FreeSurface(menus[i]);
            return 1;

        case SDL_MOUSEMOTION:
            x=event.motion.x;
            y=event.motion.y;
            for(int i=0;i<NUMMENU;i++)
            {
                if(x>=position[i].x && x<=position[i].x+position[i].w && y>=position[i].y && y<=position[i].y+position[i].h)
                    {
                    if(!selected[i])
                    {
                        selected[i]=1;
                        SDL_FreeSurface(menus[i]);
                        menus[i]=TTF_RenderText_Solid(font,labels[i],color[1]);
                    }
                }else{
                        if(selected[i])
                        {
                            selected[i]=0;
                            SDL_FreeSurface(menus[i]);
                            menus[i]=TTF_RenderText_Solid(font,labels[i],color[0]);
                        }
                      }
            }

        case SDL_MOUSEBUTTONDOWN:
            x=event.button.x;
            y=event.button.y;
            for(int i=0;i<NUMMENU;i++)
                if(x>=position[1].x && x<=position[1].x+position[i].w && y>=position[i].y && y<=position[i].y+position[i].h)
                {
                    for(int j=0;j<NUMMENU;j++)
                        SDL_FreeSurface(menus[j]);
                    return i;
                }
                break;
        case SDL_KEYDOWN:
            if(event.key.keysym.sym==SDLK_ESCAPE)
            {
                for(int i=0;i<NUMMENU;i++)
                    SDL_FreeSurface(menus[i]);
                return 0;
            }

        }

I have this error and I haven't any idea of why and what should I do to resolve this. I have tried to add break; at the end of each case but no results.

If you need more code or further information, I can give precisions.

Regards,

Upvotes: 0

Views: 1641

Answers (2)

JBarberU
JBarberU

Reputation: 1029

You are using the function void SDL_Quit(void) rather than the SDL_QUIT event type at line 3.

case SDL_Quit:
     ^^^^^^^^
        for (int i=0;i<NUMMENU;i++)
            SDL_FreeSurface(menus[i]);
        return 1;

Upvotes: 5

Sunil Bojanapally
Sunil Bojanapally

Reputation: 12658

Your case labels such as SDL_Quit/SDL_MOUSEMOTION... could not be integer constants. For example its valid if they are characters labels but not something like const char * string literals which are not integer constants.

Upvotes: 0

Related Questions