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?
Could
SDL_GetVideoInfobe returning a pointer to aconst SDL_VideoInfo?[2 minutes and a google search later]
The declaration of
SDL_GetVideoInfoI found online is: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.