Can I include only SDL_Rect.h?

Greetings

In my C++ project, many classes have an SDL_Rect struct, but don’t use anything else from SDL directly. I think compilation times would be shorter if I could include just the header for SDL_Rect instead of the entire library. Would that be a good idea, or am I going to run into some difficulties later that aren’t immediately apparent?

Alternatively, I guess I could make my own version of a rect, as it’s a very simple structure…

Best regards
BenoitRen

If the rectangle is literally the only thing you use from SDL, then
I’d suggest to just make your own Rect to avoid forcing people to get
the library just for it. I mean, seriously (this is C idiom but gives
you an idea):

typedef struct {
int x;
int y;
int w;
int h;
} Rect;

Unless you mean you’re using SDL (just through other libraries), that
is. If so, yeah I think you can get away with just including
SDL_Rect.h (what’s the official word on including SDL2 headers
directly?)

Oh looked into the file and SDL comes with some functions to test for
collisions with a rect (as well as a point and arbitrary lines).

My project uses SDL, but most classes don’t use it directly. Instead they store a pointer to an SDL_Surface and/or contain an SDL_Rect. In the former I can get away with a forward declaration, but with the latter I need to define it.

I actually use SDL 1.2, but will be using SDL 2.0 as well to support even more platforms.