SDL_arraysize(3)
π SDL_arraysize β bestie edition π
okay so this is SDL_arraysize, a lil macro from the SDL3 FUNCTIONS corner of the universe, and it's literally just here to tell you how many elements are chillin' in a static array. that's it. that's the whole job. π
β¨ NAME β¨
SDL_arraysize β the number of elements in a static array. no cap, that's the entire vibe. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
look at her. iconic. she's a macro, she's one line, she's perfect. π¦
π DESCRIPTION π
so here's the tea, bestie: this will compile but return incorrect results if you hand it a pointer to an array. π it has to be an actual array β one where the compiler already knows the size. the compiler needs to know, okay? she's not psychic. β¨
and yes, i know, this macro looks like it double-evaluates the argument π but it does that inside of sizeof, so there are no side-effects here β because expressions don't actually run any code in these cases. the argument gets peeked at, not performed. it's giving "look but don't touch." π
ngl this is the part people get wrong every single time: pointer in, garbage out. array in, correct count out. vibe check your types first, fr fr. π«Ά
β AVAILABILITY β
this macro is available since SDL 3.2.0. so if you're on anything older... not me finding out the hard way. π
and that's the whole page, bestie! π this lil slice of Simple Directmedia Layer came to you from SDL 3.4.18, dated with the SDL_arraysize(3) energy of it all β go forth and count your elements correctly. πβ¨πΈπ¦π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms