tags:

views:

26

answers:

2

When I run this bit of code through GCC I get this warning on the line where I set info to SDL_GetVideoInfo().

warning: initialization discards qualifiers from pointer target type

int main(int argc, char** argv) {
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_VideoInfo* info = SDL_GetVideoInfo();
    int SCREEN_WIDTH = info->current_w;
    int SCREEN_HEIGHT = info->current_h;
    printf("hardware acceleration? %s\n", info->hw_available == 1 ? "yes" : "no");
    printf("memory available in kilobytes: %d\n", info->video_mem);
    SDL_Quit();
    return 0;
}

Does anyone know how I can change the code so I can get around that warning?

+1  A: 

Could SDL_GetVideoInfo be returning a pointer to a const SDL_VideoInfo ?


[2 minutes and a google search later]

The declaration of SDL_GetVideoInfo I found online is:

const SDL_VideoInfo* SDL_GetVideoInfo(void);

Indeed it returns a const pointer which you convert to a non-const pointer, hence the warning. Note that you shouldn't just ignore it, since when the function wants to return a const pointer it frequently has a good reason for it - it probably doesn't make sense, or is even harmful, to modify the returned object through the pointer.

Eli Bendersky
+4  A: 

The documentation says that the function returns a const SDL_VideoInfo *, so change your code to:

const SDL_VideoInfo* info = SDL_GetVideoInfo();

Without the const, info could be used to change the value pointed to by it, but obviously, you can't do that.

Alok