Yeah, I guess so. It's just all my books (except one) tackle pointers before functions. |
So, you're trying to use functions in a 3rd-party graphics library,
before you've even learned the basics of functions? At what point did that seem like a sensible idea?
at this stage, I'm guessing that the SDL_Rect, or whatever, doesn't take SDL_Rect as an argument, it has to take a pointer as an argument? |
Um, I have no idea what you mean by that. What is SDL_Rect? A type? A function? You haven't mentioned it all in any of your posts until now, so I have no context for that statement.
OK, I've done a quick Google search, and it looks as though SDL_Rect is a type - a struct. Which means it doesn't "take" anything. A function might take an SDL_Rect as an argument, or it might take a pointer to an SDL_Rect as an argument, but without knowing what function you're talking about, I couldn't give you an answer as to why.
People have already given several reasons why a function might be defined so as to take a pointer to a struct rather than an actual struct:
1) To avoid the performance hit of copying a large struct when passing it into a function
2) To allow the function to make changes to the struct that will be reflected in the calling code - because the pointer in the calling code and the copy of the pointer in the function are both pointing to the same memory
3) To allow an "optional" parameter, because a pointer can be set to NULL.