__ARRAYCOUNT(3)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ¦‹ __ARRAYCOUNT(3) β€” like, the whole vibe πŸ¦‹

okay so this is a page from the Library Functions Manual (iykyk, that's the manual name, bestie) and honestly? it's a tiny little macro that eats πŸ’…


🌸 NAME 🌸

__arraycount β€” the macro for statically allocated arrays ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/cdefs.h>

size_t
__arraycount(x);

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea β˜• β€” the __arraycount() macro literally just returns the number of elements in a statically allocated buffer. that's it. that's the whole function. no cap. it's giving "small but mighty" energy fr fr πŸ‘‘


🌈 EXAMPLES 🌈

this is the part where it gets iconic β€” here's a typical usage of __arraycount(), bestie:

      uint8_t buf[BUFSIZE];
      size_t i;

      ...

      for (i = 0; i < __arraycount(buf); i++)
              ...

see how it just knows how many things are in buf? main character behavior honestly πŸ˜­πŸ’œ


πŸ”₯ SEE ALSO πŸ”₯

  • cdefs(3) β€” go read this one too, it's the whole squad 🫢

⭐ HISTORY ⭐

the __arraycount() macro first appeared in NetBSD 4.0 β€” a true OG, been slaying since day one πŸŽ€βœ¨


πŸ’€ reminder bestie: it only works on statically allocated arrays. don't try to be cute with it elsewhere, k? πŸ™ˆ

and that's a wrap! this lil icon comes from the Debian build of the page, dated December 16, 2010, and yep β€” it's still filed under __ARRAYCOUNT(3) in the manual. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from