SDL_size_add_check_overflow(3)

πŸ’– SDL_size_add_check_overflow(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where we do math but like, safely ✨ this one's a lil header-only baddie from SDL_stdinc.h and she is lowkey doing the most important job: catching overflow before it ruins your whole day 🫢


🌸 NAME 🌸

SDL_size_add_check_overflow</purpose> β€” add two integers, and check for overflow while you're at it πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_stdinc.h>

SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret);

like yes she's SDL_FORCE_INLINE, she's got zero chill and zero function-call overhead, we stan πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜•: if a + b would overflow, you get false back. that's it, that's the vibe check, no cap πŸ™ˆ

otherwise, she stores a + b through ret and hits you with true 🌈

it's giving "trust but verify" and honestly? iconic πŸ‘‘


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • a β€” the first addend πŸ’•
  • b β€” the second addend πŸ’•
  • ret β€” on non-overflow output, this stores the addition result. it may not be NULL β€” fr fr, do not pass NULL here, that's not the move 😭

⭐ RETURN VALUE ⭐

  • returns false on overflow πŸ’€
  • returns true if the result gets added without overflow ✨

🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. yes bestie, ANY. go wild, she's built different 🫢


🌈 AVAILABILITY 🌈

this function is available since SDL 3.2.0 β€” so if you're on anything older, sorry babes, no overflow-checking for you πŸ’”


and that's the whole page, you ate it πŸ’…βœ¨ this lil love letter comes to you from Simple Directmedia Layer, shipping as SDL 3.4.18 β€” mwah, go forth and never overflow again πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from