size_t(3type)

πŸ’– size_t β€” count of bytes πŸ’–

okay bestie, gather round, because today we're talking about size_t and ssize_t from size_t(3type), and honestly? they're the moment. ✨


πŸ“š LIBRARY

Standard C library (libc) β€” the classic, the icon, the one that raised us all. 🫢


✨ SYNOPSIS ✨

#include <stddef.h>

typedef /* ... */  size_t;
#include <sys/types.h>

typedef /* ... */  ssize_t;

two little includes, two little typedefs, one huge amount of responsibility. it's giving base of the entire C universe. πŸ’…


🌸 DESCRIPTION 🌸

  • size_t β€” bestie this one is for counting bytes. it's literally the type that comes out when you run the sizeof() operator. it's an unsigned integer type, and it can hold values in the range [0, SIZE_MAX]. no negatives, no drama, only non-negative byte counts. πŸŽ€
  • ssize_t β€” this one is for counting bytes or throwing up an error indication. it's a signed integer type, and it can store values at least in the range [-1, SSIZE_MAX]. yes queen, it goes negative. that -1 is doing so much work. 😭

πŸ–¨οΈ Use with printf(3) and scanf(3)

  • size_t β€” the length modifier for size_t in the printf(3) and scanf(3) family of functions is z, which commonly gives you %zu or %zx when you're printing size_t values. remember it. love it. 🧚
  • ssize_t β€” glibc and most other implementations give you a length modifier for ssize_t in the printf(3) and scanf(3) families too, and it's also z β€” commonly giving %zd or %zi for printing ssize_t values.
⚠️ but listen: even though z works for ssize_t on most implementations, portable POSIX programs should avoid using it β€” for example, by converting the value to intmax_t and using its length modifier (j). stay safe out there, bestie. πŸ’€

πŸ‘‘ STANDARDS πŸ‘‘

  • size_t β€” C11, POSIX.1-2024.
  • ssize_t β€” POSIX.1-2024.

certified, official, standards-approved. main character energy fr fr. πŸ”₯


πŸ¦‹ HISTORY πŸ¦‹

  • size_t β€” C89, POSIX.1-1990.
  • ssize_t β€” POSIX.1-1990.

and here's the lore drop: since POSIX.1-2008, these headers define size_t:

<aio.h>, <glob.h>, <grp.h>, <iconv.h>, <mqueue.h>, <pwd.h>, <signal.h>, and <sys/socket.h>.

and since POSIX.1-2008, these ones define ssize_t:

<aio.h>, <mqueue.h>, and <sys/socket.h>.

the glow-up was real. πŸ’œ


πŸ’… NOTES πŸ’…

size_t β€” these headers also hand you size_t:

<aio.h>, <glob.h>, <grp.h>, <iconv.h>, <monetary.h>, <mqueue.h>, <ndbm.h>, <pwd.h>, <regex.h>, <search.h>, <signal.h>, <stdio.h>, <stdlib.h>, <string.h>, <strings.h>, <sys/mman.h>, <sys/msg.h>, <sys/sem.h>, <sys/shm.h>, <sys/socket.h>, <sys/types.h>, <sys/uio.h>, <time.h>, <unistd.h>, <wchar.h>, and <wordexp.h>.

ssize_t β€” and these headers also hand you ssize_t:

<aio.h>, <monetary.h>, <mqueue.h>, <stdio.h>, <sys/msg.h>, <sys/socket.h>, <sys/uio.h>, and <unistd.h>.

that's a whole lot of includes but like… they all love you. 🌈


πŸŽ€ SEE ALSO πŸŽ€

read(2), readlink(2), readv(2), recv(2), send(2), write(2), fread(3), fwrite(3), memcmp(3), memcpy(3), memset(3), offsetof(3), ptrdiff_t(3type)


that's the whole page bestie, no cap, enjoy your byte counts πŸ’–

and a lil sign-off for the girlies keeping receipts: this is from Linux man-pages 6.20, dated 2026-02-08. slay, periodt. βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms