0

When I run

SDL_Surface* surface  = IMG_Load("*image location*");

an error pops up saying

initialization of 'SDL_Surface *' {aka 'struct SDL_Surface *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]

I don't know why this happening because shouldn't IMG_load be returning a pointer

https://www.libsdl.org/projects/SDL_image/docs/SDL_image_11.html

here is the rest of the code

#include <stdio.h>
#include <windows.h>

#include <SDL2\SDL.h>

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    int result = SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window *window = SDL_CreateWindow("bruh",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,500,500,0);
    SDL_Renderer *rend  =  SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    SDL_Surface* surface  = IMG_Load("*image location*");
    SDL_Texture* texture = SDL_CreateTextureFromSurface(rend,surface);
    SDL_FreeSurface(surface);
    SDL_RenderClear(rend);
    SDL_RenderCopy(rend,texture,NULL,NULL);
    SDL_RenderPresent(rend);
    SDL_Delay(5000);
    SDL_DestroyTexture(texture);
    SDL_DestroyRenderer(rend);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0; 
}

how do I fix this error?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Warning: I have zero knowledge about SDL. Note: Did you had a look at [this sample](https://github.com/MetaCipher/sdl-2.0-basics/blob/master/App.cpp) ? – fpiette Jun 07 '21 at 11:40
  • @fpiette i dont know c++ . what is the problem ? – sababugs112 Jun 07 '21 at 11:51
  • The error message says that `IMG_Load` returns an int and you assign it to a `SDL_Surface*`. One possibility is that you have somewhere the wrong definition for ÌMG_Load`. Search for it in the headers you have. – fpiette Jun 07 '21 at 12:02
  • @sababugs112 C and C++ are the same thing except C++ has extra OOP feature and a bigger standard library and a few things here and there. I'm absolutely shocked when someone who knows C/C++ says that he/she doesn't know the other. How much more than 5 minutes will it take to know a bit about the other language? –  Jun 07 '21 at 12:44
  • 2
    @SmGreatC C and C++ are completely different languages. Many C programs are invalid C++ programs and vice versa. They share a common history from 40 years ago, but that's about it. (And in fact, sababugs112 code above is buggy but valid C, while it would be invalid C++). – spectras Jun 07 '21 at 17:36
  • @spectras Yes, I know. It's just a few things here and there and the fixes are simple. And the similarity of a language is not calculated by how good it is compiled by the other language's compiler only. It depends upon the syntax as well which is almost the same with C and C++. Yes, they are different languages but it's so easy to learn one if you know the other, it makes no sense to not know the other. –  Jun 08 '21 at 02:18
  • A few examples of not-so-simply fixable things: `#define cbrt(X) _Generic((X), long double: cbrtl, default: cbrt, float: cbrtf)(X)`, `int array[argc]`, `auto x = 0.5;`, `*(double*)charArray`. But you are right, it is not just the syntax: the whole paradigms used and made available by the languages are completely different. Good luck implementing something like `compose(func1, func2, func3)(input)` in C. – spectras Jun 08 '21 at 07:42

1 Answers1

2

IMG_Load belongs to separate libary SDL_image. This function is declared in SDL_image.h, which you didn't include. Add that include and link with appropriate library. In C undeclared functions are allowed via implicit declarations, and implicitly declared function returns int, that's where your error comes from.

Sane compiler will issue a warning about implicit declaration. Warnings are there for a reason, read them and don't suppress warnings unless you're absolutely certain.

genpfault
  • 51,148
  • 11
  • 85
  • 139
keltar
  • 17,711
  • 2
  • 37
  • 42