I’m just a little miffed.
In SDL3: I noticed as I was setting up toggling between fullscreen that SDL_SetWindowFullscreen() now takes a SDL_bool as an argument.
My question is, why? If it took the original Uint32 flag I could xor it to toggle the flag.
If it took a regular bool then I could say fullscreenFlag != fullscreenFlag;
But SDL_TRUE and SDL_FALSE are either preprocessor-macro defined or an enum depending on if you’re on an ARM or X86_64 system.
In order to toggle, I have to implement a if/else or a ternary statement which takes extra lines, extra thought, and extra CPU processing time. You are also forced to use SDL_TRUE or SDL_FALSE in order to set the values.
Why is SDL_bool even a thing?
Why is it not a typedef or some other translation of traditional bool?
Why would it be chosen as an argument type for SDL_SetWindowFullscreen()? → the source uses a ternary to translate the SDL_bool argument back into the Uint32 flag just two lines into the function definition.
I’m only seeing the cons right now, and I know I’m being unfair. I know it’s ridiculous to worry over 6-12 extra CPU cycles, or the slight inconvenience… but why is it there to begin with?
What are the benefits of SDL_bool?
Edit: All of the above is now obsolete, Please see below.
I also don’t like SDL_bool but to be fair, SDL is a C library and it seems like you can use SDL_bool essentially like the regular bool type in C because integers are implicitly convertable to enum types so you can write things like:
As a C++ user I did not know that SDL_bool is not quite so annoying in pure C language.
Looking to the C++ portion of your response: That is definitely faster performance-wise than going through a whole if/else or ternary.
Great advice and explanation all around. Thank you Peter87!
I do still hope future SDL3 function development avoids using SDL_bool for other function arguments, but at least I have a strategy if it does creep its way in.
I must say that SDL is amazing, thank you all developers. This really is such a tiny issue, and it’s the only one I’ve had all week. You guys are awesome!