I was kind of annoyed that in SDL I have to free one surface at a time. I want to be able to free all of my surfaces at once. So I tried to write a variadic function (I was told about them by Bazzy a day or two ago when I asked about something to do with the Linux kernel source) to do it. I'm not sure whether it will work, I think not. This is what I have at the moment:
1 2 3 4 5 6 7 8 9 10 11
#include "sdl_.h"
void FreeIMG(SDL_Surface* surf, ...) {
va_list ap; // Deal with our variadic args
va_start(ap, surf);
aligned?
// Here I want to free each surface that the function was given
va_end(ap);
}
I'm not so sure that the function itself will even work. I want to free the surface pointed to by surf, but then surf should be a pointer to a pointer (?) because the surfaces given will be pointers themselves.
How can I do this?
The point of the function is to use SDL_FreeSurface(mySurface) to free an arbitrary amount of surfaces given as arguments to the function. I'm just not sure how to do it. Thanks.
I would (and do) live with it. If you're allocating more than three surfaces, it's time to put them in an array or vector, and then you can just free them in a loop.
If you wanted to use the variadic function anyway, you don't necessarily have to indicate the number. You could just specify that the argument list is a list of non-NULL pointers, and the list terminates with a NULL pointer.
FreeIMG( foo, bar, baz, NULL );
[edit] BTW, I agree 100% with helios -- please don't use variadic functions...
I just read this, http://www.catb.org/~esr/jargon/html/C/Commonwealth-Hackish.html
That sounds like how I pronounce things. Definitely char with a hard "ch" sound. However I do call ! bang, although most probably because about 80% of the people on the internet are American and about 80% of what can be read on the internet is also American.