SDL_FALLTHROUGH(3)

πŸ’– SDL_FALLTHROUGH πŸ’–

okay bestie so this is a page from the SDL3 FUNCTIONS manual, and honestly? it's giving tiny but mighty. it's literally one macro and it's here to save you from your own compiler yelling at you. iconic behavior. πŸŽ€


✨ NAME ✨

SDL_FALLTHROUGH β€” a macro that signals "yes bestie, I know this case statement has no break, and I did that on purpose." πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_begin_code.h>

#define SDL_FALLTHROUGH [[fallthrough]]

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea. C compilers have gotten way more aggressive about warning you when a switch's case block doesn't end with a break or some other flow control statement and just... flows right on into the next case's code. and lowkey? they're right to be nosy, because that's a super common accident that leads to strange bugs. 😭

but β€” and this is the plot twist β€” sometimes falling through to the next case is the correct and desired behavior. no cap. it's intentional. it's the vibe you wanted. so this symbol exists to let an app communicate that intention to the compiler, so it doesn't generate a warning. main character energy fr fr. πŸ‘‘

it's used like this:

switch (x) {
    case 1:
        DoSomethingOnlyForOne();
        SDL_FALLTHROUGH;  // tell the compiler this was intentional.
    case 2:
        DoSomethingForOneAndTwo();
        break;
}

see how it just sits there, quietly telling the compiler to chill? that's it. that's the whole macro. simple, elegant, slay. ✨


🌈 AVAILABILITY 🌈

this macro is available since SDL 3.2.0. 🫢


Simple Directmedia Layer Β· SDL 3.4.18 β€” mwah, that's the source and version, bestie. go forth and fall through on purpose. πŸ§šπŸ’œ

πŸ“¦ where this page comes from