SDL_NODISCARD(3)

πŸ’… SDL_NODISCARD(3) β€” the SDL3 FUNCTIONS girlies' edition

okay so bestie, welcome to the SDL3 FUNCTIONS manual, and today's main character is SDL_NODISCARD ✨


🌸 NAME 🌸

SDL_NODISCARD β€” a macro that tags a function's return value as critical. like, do NOT just toss it, okay?? 🫢


✨ SYNOPSIS ✨

#include <SDL3/SDL_begin_code.h>

#define SDL_NODISCARD [[nodiscard]]

πŸ¦‹ DESCRIPTION πŸ¦‹

So this macro is literally a lil hint you drop for the compiler, telling it that a function's return value should not be ignored. it's giving "hey bestie, look at this" energy. πŸ’Œ

If an NODISCARD function's return value gets thrown away β€” like, the function is called as if it returns void β€” the compiler will issue a warning. not me getting called out by the compiler 😭

Now here's the tea: while it's generally good practice to check return values for errors, often times legitimate programs do not, for good reasons. so be careful about which functions you tag as NODISCARD, fr fr. it operates best when used on a function whose failure is surprising and catastrophic; a good example would be a program that checks the return values of all its file write function calls but not the call to close the file, which it assumes incorrectly never fails. like girl. that assumption is not it. πŸ’€

Function callers that want to throw away a NODISCARD return value can call the function with a (void) cast, which informs the compiler the act is intentional. slay, consent given, no warnings today. βœ…

On compilers without nodiscard support, this is defined to nothing. so it just... vibes. no cap. πŸ“


πŸ‘‘ AVAILABILITY πŸ‘‘

This macro has been available since SDL 3.2.0. iconic behavior, honestly. ⭐


k that's the whole page bestie, go check your return values, mwah πŸ’–

this has been your girl from Simple Directmedia Layer, reporting live from SDL 3.4.18 β€” SDL_NODISCARD(3), out. πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from