Search code examples
cwindowsdl-2

c - error: expected expression before 'const' while trying to use SDL_CreateWindow


I'm trying to create a window with SDL2's latest version using documentation found here, but I two errors that i can't seem to resolve, the one in the title as well as a very confusing one.

maine.c:8:39: error: expected expression before 'const'
    8 |         SDL_Window * SDL_CreateWindow(const char *"title",
      |                                       ^~~~~
maine.c:8:22: error: too few arguments to function 'SDL_CreateWindow'
    8 |         SDL_Window * SDL_CreateWindow(const char *"title",
      |                      ^~~~~~~~~~~~~~~~

And this is my code:

#include <stdio.h>
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_video.h>

int main() {
    int SDL_Window;
    SDL_Window * SDL_CreateWindow(const char *"title",
                                int SDL_WINDOWPOS_UNDEFINED, int SDL_WINDOWPOS_UNDEFINED, 720,
                                480, 0);
}

The second error puzzles me the most because I have the required number of arguments already, which is 6.

So far I haven't really tried anything, because there used to be a lot more errors that i managed to fix trough what I know and have found online. This is what remains.


Solution

  • The first three parameters in this line are incorrectly specified:

    SDL_Window * SDL_CreateWindow(const char *"title",
                                  int SDL_WINDOWPOS_UNDEFINED, int SDL_WINDOWPOS_UNDEFINED, 720,
                                    480, 0);
    

    You should not precede parameter values with their data types in function calls. It should be:

    SDL_Window *newWindow = SDL_CreateWindow("title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 720, 480, 0);
    

    [edit] Corrected specification of the returned value. [/edit]