我正在尝试使用 clang 3.1 和选项编译此代码-Weverything
:
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
SDL_Surface* init(SDL_Surface* screen);
int main() {
SDL_Event event;
SDL_Surface* screen = NULL;
int quit = 0;
screen = init(screen);
if (screen == NULL) {
return EXIT_FAILURE;
}
while(quit == 0) {
while(SDL_PollEvent(&event)) {
if( event.type == SDL_QUIT ) {
quit = 1;
} else if( event.type == SDL_KEYDOWN ) {
switch( event.key.keysym.sym ) {
case SDLK_UP: printf("up\n"); break;
case SDLK_DOWN: printf("down\n"); break;
case SDLK_LEFT: printf("left\n"); break;
case SDLK_RIGHT: printf("right\n"); break;
default: break;
}
}
}
}
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}
SDL_Surface* init(SDL_Surface* screen) {
if( SDL_Init(SDL_INIT_EVERYTHING) == -1) {
return NULL;
}
screen=SDL_SetVideoMode(100,100,32,SDL_SWSURFACE);
return screen;
}
然后编译器向我返回以下警告
main.c:22:25: warning: 229 enumeration values not explicitly handled in switch: 'SDLK_UNKNOWN', 'SDLK_BACKSPACE',
'SDLK_TAB'... [-Wswitch-enum]
switch( event.key.keysym.sym ) {
^
在其他地方,我读过类似的错误消息,人们通过添加default
案例解决了它,但在这里你可以看到它已经存在。我真的很想在没有任何警告的情况下编译我的代码,当然这里不需要放置 229 种可能的情况。