ptrdiff_t(3type)
π ptrdiff_t(3type) β the whole vibe π
okay bestie, welcome to <ptrdiff_t>'s page, it lives in section 3type (that's the "here's a typedef, let me explain it" section, iykyk) and honestly? it's giving essential.
β¨ NAME β¨
ptrdiff_t β count of elements or array index
π LIBRARY π
Standard C library (libc) π«Ά
πΈ SYNOPSIS πΈ
#include <stddef.h>
typedef /* ... */ ptrdiff_t;
like. that's it. that's the whole declaration. typedef /* ... */ bestie, the real guts are up to your implementation π
π¦ DESCRIPTION π¦
So what IS this queen? <pink>Used for a count of elements, or an array index.</pink> That's her whole job description π
She's also <cyan>the result of subtracting two pointers</cyan> β like, literally, subtract one pointer from another and boom, you get a ptrdiff_t (the name is not subtle, it's giving "pointer difference").
And the important part, no cap: <hotpink>it is a signed integer type capable of storing values in the range [PTRDIFF_MIN, PTRDIFF_MAX]</hotpink>. SIGNED. Which means she can go negative. Which means your pointer math can go negative. Which is exactly why she exists and why size_t can't do her job π
β¨ the printf/scanf tea β¨
The length modifier for ptrdiff_t for the printf(3) and the scanf(3) families of functions is t, resulting commonly in %td or %ti for printing ptrdiff_t values. So next time you're printing one, don't be out here using %d like a menace β use %td or %ti π
π STANDARDS π
C11, POSIX.1-2024.
π HISTORY π
C89, SUSv1, POSIX.1-2001.
she's been iconic since forever, fr fr πβ¨
π SEE ALSO π
size_t(3type)β her unsigned bestie, go say hi π₯°
lowkey the cutest little typedef in <stddef.h>, tbh π¦
this page came to you courtesy of Linux man-pages 6.20, dated 2026-02-08 π stay signed, bestie, and may all your pointer differences fit in range π«Άβ
π¦ 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