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 thesizeof()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-1is doing so much work. π
π¨οΈ Use with printf(3) and scanf(3)
size_tβ the length modifier forsize_tin theprintf(3)andscanf(3)family of functions isz, which commonly gives you%zuor%zxwhen you're printingsize_tvalues. remember it. love it. π§ssize_tβglibcand most other implementations give you a length modifier forssize_tin theprintf(3)andscanf(3)families too, and it's alsozβ commonly giving%zdor%zifor printingssize_tvalues.
β οΈ but listen: even thoughzworks forssize_ton most implementations, portable POSIX programs should avoid using it β for example, by converting the value tointmax_tand 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
- Copyright 2020, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms