Yes and no. ?Using the asterisk creates a pointer, but if you don’t assign it anything, it points wherever the compiler or runtime environment decides.
Dereferencing a non-pointer variable (using ‘&’) is good in this case because if you used a pointer directly, then you are responsible for allocating and freeing the memory for that variable. ?If it’s not a pointer, then the runtime environment deals with memory management for you, which is always preferable.
Ah, that makes a lot of sense. Thanks!
P.S. Yes, I know C is a lower-level language than Python. I have plenty of experience with higher level languages using SDL and similar libraries. I have been learning C over the past month from online tutorials. I know I’m going to make mistakes but I’m ready to dive into writing C code even if I?don’t?understand everything yet. That’s how you learn. I understand the wiki is API documentation and not tutorials, but examples are helpful to see how the various components work together, rather than referenced in isolation.
– AndrewOn November 1, 2013 at 10:49:24 AM, Alex Barry (alex.barry at gmail.com) wrote:
Yes and no. ?Using the asterisk creates a pointer, but if you don’t assign it anything, it points wherever the compiler or runtime environment decides.
Dereferencing a non-pointer variable (using ‘&’) is good in this case because if you used a pointer directly, then you are responsible for allocating and freeing the memory for that variable. ?If it’s not a pointer, then the runtime environment deals with memory management for you, which is always preferable.
On Fri, Nov 1, 2013 at 1:39 PM, Andrew Havens wrote:
I thought that prefixing a variable with an asterisk would create a pointer. Would this be the same thing?
SDL_Rect *rect;
?
SDL_FillRect(screenSurface, rect, ?)
It’s true, I’m not super familiar with C. I’m still getting used to the syntax. Unfortunately, the SDL wiki doesn’t provide many basic examples.
– Andrew
On November 1, 2013 at 10:30:32 AM, Mason Wheeler (masonwheeler at yahoo.com) wrote:
That’s because it wants a pointer to the rect, not the rect itself.
Mason
On Friday, November 1, 2013 10:19 AM, Andrew Havens wrote:
Unfortunately, that did not work. I get this error:
error: incompatible type for argument 2 of ?SDL_FillRect?
Andrew
On November 1, 2013 at 9:57:43 AM, Alex Barry (alex.barry at gmail.com) wrote:
SDL_Rect is a struct, and in C, iirc, you can’t use default constructors on structs.
SDL_Rect rect; //(0,0,100,100)
rect.x = 0;
rect.y = 0;
rect.w = 100;
rect.h = 100;
SDL_FillRect(screenSurface, rect, SDL_MapRGB(screenSurface->format, 0x00, 0x00, 0x00));
That should fix it for you, I think.
On Fri, Nov 1, 2013 at 12:28 PM, Andrew Havens <@Andrew_Havens> wrote:
Hello,
I’m getting started with SDL and am having a hard time finding tutorials that are updated to work with version 2.0. I’ve got the basic setup/teardown working, now I would like to do something simple like draw a square on the screen. The example that I copied is not working.
//Get window surface
SDL_Surface *screenSurface = SDL_GetWindowSurface(window);
//Fill the surface white
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
//create a square
SDL_FillRect(screenSurface, SDL_Rect(0,0,100,100), SDL_MapRGB(screenSurface->format, 0x00, 0x00, 0x00));
It correctly fills the screen white, but fails on the call to?SDL_Rect:
error: expected expression before ?SDL_Rect?
How do I correctly draw a square using SDL 2.0?
Thanks,
– Andrew
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org