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