SDL, and SDL_Rect

Hey guys,

Working on a project with SDL in VC2012 express. I'm having an issue using SDL_Rect. Here's a snippet of code that I'm trying to implement :

1
2
3
4
5
6
...
int xvar;
int yvar;
SDL_Rect example;
example.x = xvar; //line 5
example.y = yvar; //line 6 


Looking at tutorials all around, this code should work. I'm using the standard library, SDL2, and all that, however when writing the example.x/y portion i get a warning stating "This declaration has no storage class or type specifier".

Compiling the code, it says, "expected a ; before . on line 5 and 6." and "example : redefinition; different basic types.".

Here's the definition of SDL_Rect if it helps :

1
2
3
4
5
6
...
typedef struct SDL_Rect
{
    int x, y;
    int w, h;
} SDL_Rect;


Am I doing something wrong?


EDIT : Messed around with it a little more, decided to put the same code into a function instead of globally, and it worked. Seems like you can't assign values outside of the declaration of the variable otherwise the compiler thinks you're trying to re-declare it.
Last edited on
outside of a function you can declare and initialize a variable.
Anything else like assigning a new value like on line 5/6 you can do only within a function.
Topic archived. No new replies allowed.